Elliott B
Elliott B

Reputation: 1199

Why does PHP give Permission Denied errors when writing file?

I'm running XAMPP 1.8.2 with the default PHP 5.4.19 on OS X 10.8.5. My PHP application is supposed to have read/write access to a certain local directory, but it's not working. For testing, I distilled it down to a very simple script:

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

Warning: file_put_contents(/Volumes/RAID/AT_RISK/copra/uploadedfiles/file.txt): failed to open stream: Permission denied in /Applications/XAMPP-1.8.2/xamppfiles/htdocs/filetest.php on line 4

I've tried this command, but it doesn't help.

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

Here you can see the permissions for yourself:

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

Upvotes: 0

Views: 2073

Answers (1)

Elliott B
Elliott B

Reputation: 1199

Silly me. Although the folder had correct permissions, the volume itself (/Volumes/RAID) was 700. Problem solved.

Upvotes: 1

Related Questions