PHP即使具有777权限也无法写入文件 [英] PHP Cannot write to file even though it has 777 permissions

查看:105
本文介绍了PHP即使具有777权限也无法写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将php文件写入驻留在同一文件夹中的文件. php文件及其试图写入的文件都将其权限设置为777(它是Linux服务器)以及它们所在的文件夹.每当我以"w"或"w +"模式调用fopen()时,该函数仅返回false.它在我学校的网络服务器上,因此我无法获得root用户访问权限,无法将文件的所有者更改为与apache相同的用户.有人知道怎么了吗?

Im trying to make a php file write to a file that resides in the same folder. Both the php file and the file its trying to write to have their permissions set to 777 (its a linux server) as well as the folder they reside in. Whenever I called fopen() with the 'w' or 'w+' mode, the function just returns false. Its on my school's webserver, so there is no way I can get root access to change the owner of the file to the same user as apache. Does anyone know whats wrong?

更新: 作为测试,我正在使用以下代码:

Update: As a test, I was using this code:

$handle = fopen("test.txt", 'w');
if($handle === FALSE)
    echo "\nfailed";
else
    echo "\nsuccess";
fclose($handle);

现在启用了错误报告的输出是:

The output now with error reporting enabled is:

Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /<snip>/public_html/test.php on line 58
failed
Warning: fclose(): supplied argument is not a valid stream resource in /<snip>/public_html/test.php on line 63

上面是我从php网站复制的一些代码,用于fileperms()函数,该函数检查文本文件的权限及其报告-rwxrwxrwx

Above that is some code I copied from the php website for the fileperms() function which checks the permissions of the text file, and its reporting -rwxrwxrwx

相关文件的ls -al输出为

The ls -al output of the relevant files is

ls -al *test*
-rwxrwxrwx   1 mag5     30          1475 Dec  9 00:02 test.php*
-rwxrwxrwx   1 mag5     30             8 Dec  8 14:54 test.txt*

我也不知道这是否重要,但是我的学校使用的是称为Andrew文件系统的文件( http: //en.wikipedia.org/wiki/Andrew_File_System ).

Also Im not sure if this matters, but my school uses something called the Andrew File system (http://en.wikipedia.org/wiki/Andrew_File_System).

推荐答案

Telanor,AFS是一个非常重要的线索.

Telanor, AFS is a very big clue.

AFS(Andrew文件系统)具有完整级别的目录权限,其权限范围超过了传统的UNIX文件系统.检查目录上的AFS权限,以确保您能够访问目录中的文件.同样,与您的权限无关紧要,但与Web服务器的权限(或更确切地说,它在其下运行的用户ID)无关.自从我使用AFS已有很长时间了,所以我不知道这些命令可以用来检查目录权限.

AFS (Andrew File System) has a whole level of directory permissions beyond that of traditional unix filesystems. Check AFS permissions on the directory to make sure you have the ability to access files in the directory. Also it may not be your permissions that matter, but the permissions of the webserver (or rather the userid it's running under). It's been a long time since I used AFS so I don't know the commands offhand to check directory permissions.

这篇关于PHP即使具有777权限也无法写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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