fopen()无法打开流:权限被拒绝,但权限应该是有效的 [英] fopen() fails to open stream: permission denied, yet permissions should be valid
问题描述
所以,我有这个错误:
Warning: fopen(/path/to/test-in.txt) [function.fopen]: failed to open stream: Permission denied
执行 ls - l
在 test-in.txt
的目录中产生以下输出:
Performing ls -l
in the directory where test-in.txt
is produces the following output:
-rw-r--r-- 1 $USER $USER 1921 Sep 6 20:09 test-in.txt
-rw-r--r-- 1 $USER $USER 0 Sep 6 20:08 test-out.txt
为了超越这个,我决定执行以下操作:
In order to get past this, I decided to perform the following:
chgrp -R www-data /path/to/php/webroot
然后做了:
chmod g + rw / path / to / php / webroot
然而,当我运行php5脚本打开文件时,我仍然收到此错误。为什么会这样?我通过CGI尝试使用LAMP和切诺基,所以不能这样。
Yet, I still get this error when I run my php5 script to open the file. Why is this happening? I've tried this using LAMP as well as cherokee through CGI, so it can't be this.
是否有某种解决方案?
编辑
我还要补充一点,我现在只是通过localhost开发。
I'll also add that I'm just developing via localhost right now.
更新 - PHP fopen()
行
Update - PHP fopen()
line
$fullpath = $this->fileRoot . $this->fileInData['fileName'];
$file_ptr = fopen( $fullpath, 'r+' );
我还应该提一下,如果可能,我想坚持使用切诺基。关于为Apache / Cherokee设置文件权限的问题是什么?
I should also mention I'd like to stick with Cherokee if possible. What's this deal about setting file permissions for Apache/Cherokee?
推荐答案
检查运行PHP的用户是否具有X权限在文件路径的每个目录上。
它将需要它来访问文件
Check if the user that PHP runs under have "X" permission on every directory of the file path.
It will need it to access the file
如果你的文件是: / path / to / test-in.txt
你应该拥有X权限:
If your file is: /path/to/test-in.txt
You should have X permission on:
-
/ path
-
/ path / to
/path
/path/to
和 /path/to/test-in.txt的读取权限
这篇关于fopen()无法打开流:权限被拒绝,但权限应该是有效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!