Delete a File

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chris98
Forum Contributor
Posts: 103
Joined: Tue Jun 11, 2013 10:47 am
Location: England, United Kingdom

Delete a File

Post by chris98 »

Hello, I have created this code below, but though it works, it spits out a rather annoying error message.

It works, but the fact is it just gives out an error message and it's annoying.

It says "Permission denied" but it works.How?


<?php array_map('unlink', glob("uploader/uploads/".$file_name."".$file_extension."")); ?>



(The variables are defined earlier in the document, and it does delete the file I want, but it just randomly gives that error.)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Delete a File

Post by requinix »

What are the values of $file_name and $file_extension? What files does glob() find? Are any of them also directories? Are you sure it actually did delete every file you expected it to?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Delete a File

Post by AbraCadaver »

I don't know about the error, but why use glob? It looks like you are only deleteing one file unless one of the vars contains something like .*

Code: Select all

unlink("uploader/uploads/".$file_name.$file_extension);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply