权限被拒绝-PHP取消链接 [英] permission denied - 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]:权限被拒绝
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,则可以执行取消链接,但必须设置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.
这篇关于权限被拒绝-PHP取消链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!