【发布时间】:2016-04-12 07:47:12
【问题描述】:
我已经使用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';
}
但我在unlink 收到Permission denied 错误
我检查了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?
【问题讨论】:
-
文件夹需要有可执行权限,显然没有。
-
检查上传的文件是否属于运行 PHP 脚本的同一系统用户(通常为“www”、“httpd”或“apache”)。
-
如何查看用户?
-
@AD7six 我检查了
is_writable的文件夹。返回真。还添加了0777到文件夹以及仍然无法正常工作