文件存在但不会取消链接 (PHP)

发布于 2024-10-31 05:48:37 字数 1469 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

丢了幸福的猪 2024-11-07 05:48:38

好吧,我是个傻瓜,发现发布的变量名称已更改,应该是“image”而不是“image_name”......

抱歉浪费你们的时间!

Ok I am a dumbass and found out that the posted variable name has changed and should have been 'image' instead of 'image_name'....

Sorry for wasting you guys' time!

尴尬癌患者 2024-11-07 05:48:38

@Rick:如果去掉警告抑制 @,PHP 是否会返回访问被拒绝的错误消息?如果是这样,那就是问题所在。尝试

if (file_exists(TEMPLATEPATH . '/uploads/' . $_POST['image_name'])) {
   chmod(TEMPLATEPATH.'/uploads/'.$_POST['image_name']), 0755);

   if (unlink(TEMPLATEPATH . '/uploads/' . $_POST['image_name'])) {
        echo "true";
    } else {
        echo "false";   
    }
} else {
    echo "false";   
}

@Rick: If you take out the warning-suppressing @, does PHP return an access denied error message? If so, that's the problem. Try

if (file_exists(TEMPLATEPATH . '/uploads/' . $_POST['image_name'])) {
   chmod(TEMPLATEPATH.'/uploads/'.$_POST['image_name']), 0755);

   if (unlink(TEMPLATEPATH . '/uploads/' . $_POST['image_name'])) {
        echo "true";
    } else {
        echo "false";   
    }
} else {
    echo "false";   
}
安静 2024-11-07 05:48:38

正如其他人所说,您需要拥有适当的权限才能删除。具体来说,您需要写权限。试试这个:

$filename = TEMPLATEPATH.'/uploads/'.$_POST['image_name'];
if(is_writable($filename)) {
  unlink($filename)
} else {
  // error handling. You can check which condition is failing here
}

As others are saying, you need to have proper permissions to delete. Specifically, you need write permission. Try this:

$filename = TEMPLATEPATH.'/uploads/'.$_POST['image_name'];
if(is_writable($filename)) {
  unlink($filename)
} else {
  // error handling. You can check which condition is failing here
}
不知所踪 2024-11-07 05:48:37

即使该文件存在,也不意味着您有权删除它。

您应该删除@运算符,它消除了潜在的错误——这可能非常有趣。

And if you don't want error messages to be displayed to the user, you should :

Even if the file exists, it doesn't mean you have the permissions to delete it.

You should remove the @ operator, which is silencing a potential error -- which is probably quite interesting.

And if you don't want error messages to be displayed to the user, you should :

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文