我在数据库中保存了图像的路径。要删除这些图像,我从数据库中获取路径
这很好用,直到我在路径中添加了两个文件夹。
到目前为止,我的数据库中的路径看起来像这样(工作!):<br/>
/var/www/myproject/public/images/550d744bd91d16.7869
现在,它看起来像这样(不工作!):/var/www/myproject/public/images/5/profile/550d744bd91d16.7869
我的代码
$folder_name = /var/www/myproject/public/images/ . $_GET['user_id'] . '/';
$profile_folder = $folder_name . 'profile/';
chmod($folder_name, 0777);
chmod($profile_folder, 0777);
// Get the images file path
$database = DatabaseFactory::getFactory()->getConnection();
$query = $database->prepare("SELECT image_path FROM images WHERE image_id = :image_id AND user_id = :user_id LIMIT 1");
$query->execute(array(':image_id' => $image_id, ':user_id' => Session::get('user_id')));
$img_path = $query->fetch();
// Convert array to string
$path = $img_path->image_path;
$file = $path . '.jpg';
if (file_exists($file)) {
// Delete the image file on the server
unlink($file);
} else {
echo 'An error occured';
return false;
}
到目前为止我尝试了什么
路径绝对是正确的。我在数据库中进行了三次检查并多次输出变量
因此,我认为它必须是目录权限,但是,我添加了代码的权限,没有任何改变。
我没有收到任何错误消息,我将无法感谢任何对此的帮助!
的摘要
file_exists(unlink($file))
返回FALSE。
unlink($file)
返回TRUE。
文件权限:
images drwxrwxrwx
5 drwxrwxrwx
profile drwxrwxrwx
image.jpg -rwxrwxrwx