2

代码在 fopen() 处阻塞:

<?php 
  ini_set('display_errors',1);
  error_reporting(E_ALL);
  $fp = fopen("/path/to/file/some_file.txt","a") or die("can't open file");
  fwrite($fp,"some text");
  fclose($fp);
?>

结果网页显示:

“警告:fopen(/path/to/file/some_file.txt)[function.fopen]:无法打开流:第 5 行的 /var/www/html/test.php 中的权限被拒绝无法打开文件”

我尝试使用文件权限,但无济于事。我更改了用户/组chown apache:apache some_file.txt并更改了权限chmod 755 some_file.txt。以下是相关结果ls -l /path/to/file/

-rwxr-xr-x 1 apache apache 0 Apr 12 04:16 some_file.txt
4

4 回答 4

4

不要忘记,即使 Apache 被授予读取文件的权限,您也必须授予 Apache 对所有父目录的访问权限。

/path/to/file/
/path/to
/path

都需要授予 Apache 至少“读取”权限。

于 2010-04-12T16:07:56.017 回答
3

你确定那apache是用户实际运行你的 PHP 吗?

并且:确保apache用户可以访问some_file.txt文件系统,并且不会被上面目录的某些访问限制阻止some_file.txt

于 2010-04-12T09:05:09.720 回答
2

在您修复错误之前,很高兴知道要修复哪个错误。
在脚本顶部添加这些行,然后重试

ini_set('display_errors',1);
error_reporting(E_ALL);

PHP会告诉你,有什么问题

于 2010-04-12T09:10:33.173 回答
1

"a"表示您要追加,需要与写入相同的权限。

每个人至少需要 666 个权限才能写入。或者将文件所有者更改为服务器组(Ubuntu 上的 www-data)。并设置所需的权限。

这是权限计算器

如果这没有帮助,请检查safe_mode

于 2010-04-12T09:05:55.150 回答