Delete image from server

I used the unlink method to delete the image

This image is located only in this folder.

$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, which is my default name (client server name). I cannot delete images from a folder on this server. The same code that I checked on my localhost system, here the image is deleted. But in the web04 server, the image is not deleted.

Please help me. Thanks at Advance.

+4
source share
3 answers

I put a ticket on my web hosting server. They gave permission to delete the image. Now the image will be deleted.

Thanks to everyone who helps me in this matter.

0
source

determine the root directory:

$root_directory = '/home/myuser/htdocs';

:

if(unlink($root_directory.$_GET['file']))
    echo "File Deleted.";


 else
        echo "Couldn't delete the File.";
+4

" " , , :

  • , .
  • This file is re-created again by any agent / event.

It seems that unlink really deletes the file when you do a 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';
}
+2
source

Source: https://habr.com/ru/post/1693738/


All Articles