Reputation: 306
I used a unlink method to delete the image
This image is located in this file folder only.
$filename = "warning-icon.jpg";
if (file_exists($filename)) {
unlink($filename);
echo 'File '.$filename.' has been deleted';
} else {
echo 'Could not delete '.$filename.', file does not exist';
}
But the image is not deleted.
i have a server name called web04 that is my default server name (Client server name). I can't delete the images from the folder in this server. Same code i have checked in my system localhost, here image get deleted. But in web04 server, Image not get deleted.
Please help me. Thanks in Advance.
Upvotes: 3
Views: 461
Reputation: 306
I have put a ticket to my web hosting team server. They gave a permission to delete the image. Now the image get deleted.
Thanks to all, those who are help me in this issue.
Upvotes: 0
Reputation: 511
define root directory:
$root_directory = '/home/myuser/htdocs';
Now delete the file:
if(unlink($root_directory.$_GET['file']))
echo "File Deleted.";
else
echo "Couldn't delete the File.";
Upvotes: 4
Reputation: 562
As echo displayed "File name has deleted" and file still in directory, there are maybe another reasons like:
Looks like unlink really delete file as you make "file_exists" check. Maybe try another check?
$filename = "warning-icon.jpg";
if (file_exists($filename)) {
unlink($filename);
echo 'File '.$filename.' has been deleted';
if (file_exists($filename)) {
echo "still exists!!!";
}
} else {
echo 'Could not delete '.$filename.', file does not exist';
}
Upvotes: 2