fopen()无法打开流:权限被拒绝,但权限应该有效

zeb*_*und 4 php linux io permissions fopen

所以,我有这个错误:

Warning: fopen(/path/to/test-in.txt) [function.fopen]: failed to open stream: Permission denied
Run Code Online (Sandbox Code Playgroud)

ls -ltest-in.txtis 所在的目录中执行产生以下输出:

-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
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我决定执行以下操作:

chgrp -R www-data /path/to/php/webroot
Run Code Online (Sandbox Code Playgroud)

然后做了:

chmod g+rw /path/to/php/webroot

但是,当我运行php5脚本打开文件时,我仍然会收到此错误.为什么会这样?我用LAMP和切诺基通过CGI试过这个,所以不能这样.

有某种解决方案吗?

编辑

我还要补充一点,我现在正在通过localhost进行开发.

更新 - PHP fopen()

$fullpath = $this->fileRoot . $this->fileInData['fileName'];

$file_ptr = fopen( $fullpath, 'r+' );
Run Code Online (Sandbox Code Playgroud)

我还要提一下,如果可能,我想坚持使用切诺基.关于为Apache/Cherokee设置文件权限的问题是什么?

Iza*_*ack 7

检查运行PHP的用户是否对文件路径的每个目录都具有"X"权限.
它将需要它来访问该文件

如果您的文件是:/path/to/test-in.txt
您应该拥有X权限:

  • /path
  • /path/to

并阅读权限 /path/to/test-in.txt