【问题标题】:Why does PHP give Permission Denied errors when writing file?为什么 PHP 在写入文件时会出现 Permission Denied 错误?
【发布时间】:2013-10-20 23:04:20
【问题描述】:

我在 OS X 10.8.5 上使用默认 PHP 5.4.19 运行 XAMPP 1.8.2。 我的 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):无法打开流:/Applications/XAMPP-1.8.2/xamppfiles/htdocs/filetest.php 第 4 行中的权限被拒绝

我试过这个命令,但是没有用。

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

【问题讨论】:

  • 可能是个愚蠢的想法,但您可以尝试将 www-data 添加到文件夹/文件本身,这可能会奏效。
  • 我不明白你的意思。
  • 我认为这可能与“/Volumes”符号有关。显然 php 无法使用 fileperms() 从该 file.txt 读取,但它可以从 /etc/passwd 读取就好了。
  • 抱歉,我的回复太晚了,但我想将组更改为 www-data,例如 chgrp www-data file.txt

标签: php macos permissions


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多