PHP即使具有777权限也无法写入文件

编程入门 行业动态 更新时间:2024-10-26 20:28:04
本文介绍了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/wiki/Andrew_File_System ).

Also Im not sure if this matters, but my school uses something called the Andrew File system (en.wikipedia/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权限也无法写入文件

本文发布于:2023-11-11 06:46:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:权限   文件   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!