权限设置为777和文件仍然不可写 [英] Permissions set to 777 and file still not writeable

查看:1225
本文介绍了权限设置为777和文件仍然不可写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置文件权限为777但我无法写入用PHP文件。

I have set file permissions to 777 yet I cannot write to the file with PHP.

我可以明确地在我的FTP客户端看到该文件具有0777的权限,当我做的:

I can clearly see in my FTP client that the file has 0777 permissions and when I do:

echo (true === is_writable('file.txt')) ? 'yes' : 'no';

我得到'不';

I get 'no';

我也试过:

echo (true === chmod('file.txt', 0777)) ? 'yes' : 'no';

使用相同的结果。

目录列表中是这样的:

public_html
    public          0777
        css         0755
        js          0755
        file.txt    0777

和我使用.htaccess文件的所有流量重定向到公众子文件夹。当然,我已经排除重写文件(它是从我查了浏览器访问):

And I'm using .htaccess file to redirect all traffic to the public subfolder. Of course, I have excluded the file from rewriting (it is accessible from the browser I checked):

RewriteRule  ^(file).*  - [L]

这是为什么?

推荐答案

我猜Apache运行于不同的用户/组不是用户/组拥有的文件。在这种情况下,文件本身必须是 0777

I guess Apache runs as a different user/group than the user/group owning the file. In which case, the file itself needs to be 0777.

公共仅需要 0777 如果您计划使用PHP将文件添加到该文件夹​​。即使该文件夹本身并不 0777 ,如果该文件的文件夹,至少有 5 为用户( 读取/执行),你应该能够写入文件中。

public only needs to be 0777 if you plan on adding files to the folder using PHP. Even if the folder itself is not 0777, if the file is and the folder has at least 5 for the user (read/execute), you should be able to write to the file.

在最后,你的文件树应该是这样的:

In the end, your file tree should look like this:

public_html
    public
        file.txt  0777

当然,你将无法使用PHP来改变这些权限,但你可以从你的FTP客户端这样做。

Naturally, you won't be able to change those permissions using PHP, but you can do so from your FTP client.

如果仍不能正常工作,PHP可以在安全模式下运行,或者您可能会使用扩展名,例如PHP了Suhosin。你可能会得到更好的结果改变文件的所有者运行脚本相同的用户/组。

If it still isn't working, PHP might be running in safe mode or you might be using an extension such as PHP Suhosin. You might get better result changing the owner of the file to the same user/group that is running the script.

要得到执行用户的用户/组ID,您可以使用以下内容:

To get the user/group id of the executing user, you may use the following:

<?php
echo getmyuid().':'.getmygid(); //ex:. 0:0
?>

然后,您可以使用 CHOWN (终端)来更改文件的所有者:

Then, you may use chown (in the terminal) to change the owner of the file:

> chown 0:0 file.txt

这篇关于权限设置为777和文件仍然不可写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆