fopen()无法打开流:权限被拒绝,但权限应该是有效的 [英] fopen() fails to open stream: permission denied, yet permissions should be valid

查看:4742
本文介绍了fopen()无法打开流:权限被拒绝,但权限应该是有效的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有这个错误:

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屋!

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