PHP: unlink cannot delete file even the file exists and writable

Give the full path instead, like

$filename = dirname(__FILE__) . '/upload/test.png';

Then try this,

if (is_file($filename)) {

   chmod($filename, 0777);

   if (unlink($filename)) {
      echo 'File deleted';
   } else {
      echo 'Cannot remove that file';
   }

} else {
  echo 'File does not exist';
}

If you are saying that everything is ok and no permission issue then you can try this way too:

unlink(realpath("upload/test.png"));

Tags:

Php

Unlink