我使用php GD library
来调整图片大小并首先将它们存储在本地。
调整大小后,我将这些图片上传到server
。
我想立即从本地目录中删除图片。
这是我的代码..
$image_name = $_FILES["imagePath"]["name"];
$newimg = 'app/templates/'.TEMPLATE.'/memberimages/'.$image_name;
$filename = realpath($newimg);
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';
}
但我在Permission denied
unlink
错误
我检查了memberimages
文件夹php is_writable()
,该文件夹也返回true。
我也试过exec()
。没有错误,但无法删除图像。
需要帮助。
If I am able to save images in that folder then delete should work as well. Is it really permissions related issue?
答案 0 :(得分:0)
unlink()
/ delete的文件没有打开。如果文件是.exe
等,请同时签入 Windows任务管理器->进程,然后将其杀死(在这种情况下,我认为该文件是图像)。确定未打开文件1后,请尝试以下代码:
// Check existence of file
if (file_exists($cekFile1)) {
// make sure you have permission to delete file
if(chmod($fileDir, 0777)){
if(!unlink($cekFile1)){
echo "unlink is fail !";
}
}else{
echo "chmod is fail";
}
// owner have read, write, execute rights.
// owner's user group only have read rights.
// everybody else only have read rights.
chmod($fileDir, 0744);
}
有关chmod()
的更多信息,请查看以下参考文献: