我写了这段代码:
if (file_exists("testfile.rtf")) echo "file exists.";
else echo "file doesn't exist.";
$fh = fopen("testfile.rtf", 'w') or die("impossible to open the file");
$text = <<< _END
Hi buddies,
I write for the first time
in a PHP file!
_END;
fwrite($fh, $text) or die("Impossible to write in the file");
fclose($fh);
echo ("writing in the file 'testfile.rtf' succeed.");
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,它说:
fopen(testfile.rtf):无法打开流:第64行/Applications/XAMPP/xamppfiles/htdocs/test/test1.php中的权限被拒绝无法打开文件
我在我的MAC上使用XAMPP在本地服务器上工作.
我找到了几个主题,其中一些人有同样的问题,并使用一个名为"chmod 777"的东西解决了它,但我不知道这意味着什么,在哪里写这个,等等.
您看到的错误只是意味着您的php脚本没有打开testfile.rtf进行写入的权限.
在获得权限问题的任何时候都不要 "chmod 777",这可能会在以后引入安全问题!相反 - 为正确的用户提供正确的权限.
在这种情况下:
由于您运行的是XAMPP,因此您需要确保您的Web服务器获得对您尝试在其中创建新文件和/或编辑现有文件的特定路径的写入权限.
在OSX和apache的情况下,我相信网络服务器的用户被命名为"_www".
这是一个小例子(您可能需要根据需要进行更改):
sudo chown -R _www:_www /path/to/folder
Run Code Online (Sandbox Code Playgroud)
上面的示例将给出_www(webserver)对/ path/to /文件夹及其中所有文件的所有权.
另外:在执行任何基于命令行的管理之前,您可能想要阅读一些关于unix命令的信息,例如chown,chmod等.
https://www.techonthenet.com/linux/commands/chown.php https://www.techonthenet.com/linux/commands/chmod.php
希望它有点帮助!
| 归档时间: |
|
| 查看次数: |
9275 次 |
| 最近记录: |