我一直在试图弄清楚为什么unlink
不起作用。我尝试查看之前的stackoverflow问题和答案,但没有成功。需要删除的确切文件名是'upload/test.png'
。
首先,我检查文件是否存在。
$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
并确保你有写入权限。 - GroovyCarrot