I've been trying to figure out why unlink
is not working. I've tried stackoverflow previous questions and answers but no luck. The exact filename that needs to be deleted is 'upload/test.png'
.
First I made a check if file exists.
$filename = 'upload/test.png';
if(file_exists($filename)){
// file_exists returns true
if(is_writable($filename)){
// is_writable also returns true
if(unlink($filename)){
echo 'file deleted';
}
else{
echo 'cant delete file';
print_r(error_get_last());
// this gives me
// unlink() function.unlink: No such file or directory
}
}
}
./upload/test.png
and make sure you have write permissions? – Sharrisharron