dongzongxun8491 2012-05-04 22:14
浏览 52
已采纳

PHP从子目录中删除文件?

I have a PHP script that deletes files. It can delete files from my root directory, but when I try to delete from a subdirectory, it says "Permission denied". I know the file exists and PHP can access it because I can read and write to the file, but I can't delete it. Why?

EDIT: If this is relevant, I am using Zymic hosting. But I have another site on Zymic where the deleting works fine. I don't get it...

EDIT: I use ajax to access the PHP file with the code to delete, and the ajax sends the file name to delete. I know the file name it sends is correct, because the warning message prints it for me. The PHP code is simply:

$file=$_POST['file'];
echo unlink($file);

EDIT: I fixed it! I don't know why this worked, but I FTP-chmodded the directory from 755 to 775 Can anyone tell me why it worked?

  • 写回答

3条回答 默认 最新

  • donglu9134 2012-05-04 22:18
    关注

    To delete the file you need write permissions to the folder that contains it, check that first.

    CHMOD xxx -> Owner Group Other

    first case: 755 - Owner (read, write, execute), Group (read, execute), Other (read, execute)

    second case: 775 - Owner (read, write, execute), Group (read, write, execute), Other (read, execute)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作