权限被拒绝 - php unlink

2022-01-04 00:00:00 permissions php unlink

我有两个文件:b.php 和 test.txt

I have two files: b.php and test.txt

<?php 
$b = "test.txt";
unlink($b);
?>

错误是:警告:unlink(test.txt) [function.unlink]: Permission denied

and the error is: Warning: unlink(test.txt) [function.unlink]: Permission denied

为什么?b.php 和 test.txt 是 777 同组/登录

why? b.php and test.txt is 777 and the same group/login

如果我在父目录上设置 777 我可以执行 unlink 但我必须设置 777 并返回到 755?

if I set 777 on the parent directory I can execute unlink but i have to set 777 and back to 755?

推荐答案

您(就像在运行 b.php 的进程中一样,您可以通过 CLI 或网络服务器) 需要对文件所在目录的写访问权限.您正在更新目录内容,因此对该文件的访问权限是不够的.

You (as in the process that runs b.php, either you through CLI or a webserver) need write access to the directory in which the files are located. You are updating the directory content, so access to the file is not enough.

请注意,如果您使用 PHP chmod() 函数将文件或文件夹的模式设置为 777,则应使用 0777以确保该数字被正确解释为八进制数.

Note that if you use the PHP chmod() function to set the mode of a file or folder to 777 you should use 0777 to make sure the number is correctly interpreted as an octal number.

相关文章