为什么 PHP 在写入文件时给出权限被拒绝错误


Why does PHP give Permission Denied errors when writing file?

我在OS X 10.8.5上运行XAMPP 1.8.2,默认PHP 5.4.19。我的PHP应用程序应该对某个本地目录具有读/写访问权限,但它不起作用。 为了进行测试,我将其提炼为一个非常简单的脚本:

<?php
$file = "/Volumes/RAID/AT_RISK/copra/uploadedfiles/file.txt";
$current = "hello world'n";
file_put_contents($file, $current);
?>

警告:file_put_contents(/Volumes/RAID/AT_RISK/copra/uploadedfiles/file.txt):无法打开流:第 4 行的/Applications/XAMPP-1.8.2/xamppfiles/htdocs/filetest.php 中的权限被拒绝

我试过这个命令,但它没有帮助。

sudo chmod -R 777 /Volumes/RAID/AT_RISK/copra/

在这里,您可以看到自己的权限:

$ pwd
/Volumes/RAID/AT_RISK/copra/uploadedfiles
$ ls -l
total 32
-rwxrwxrwx  1 elliott  staff  7 Oct 12 22:31 file.txt

愚蠢的我。尽管文件夹具有正确的权限,但卷本身 (/Volumes/RAID) 为 700。问题解决了。