代码在 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
最佳答案
不要忘记,即使 Apache 被授予读取文件的权限,您也必须授予 Apache 对所有父目录的访问权限。
/path/to/file/
/path/to
/path
都需要授予 Apache 至少“读取”权限。
关于php - 无法在php中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2620838/