【发布时间】:2011-02-06 22:18:02
【问题描述】:
代码在 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
【问题讨论】:
-
try chmod 777 some_file.txt只是为了确定——也许您的 apache 服务器没有以 apache 用户身份运行?另外,我假设您的 chown 和 chmod 命令指的是 some_file.txt 而不是 test.php?您对 test.php 的写权限与它是否可以读/写 some_file.txt 无关 -
是的,chown 和 chmod 命令是在 some_file.txt 上完成的,我只是搞砸了我的问题。谢谢,现在修好了。当我回到工作岗位时,我会尝试使用 777 或 666 更安全一些,但我当然不想为我要写入的每个文件都这样做。
标签: php apache file-io permissions fopen