Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fopen:无法打开流:在Mac上的PHP中权限被拒绝_Php_Macos - Fatal编程技术网

fopen:无法打开流:在Mac上的PHP中权限被拒绝

fopen:无法打开流:在Mac上的PHP中权限被拒绝,php,macos,Php,Macos,我写了这段代码: 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!

我写了这段代码:

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.");
if(文件存在(“testfile.rtf”))回显“文件存在”;
else echo“文件不存在。”;
$fh=fopen(“testfile.rtf”,“w”)或die(“无法打开文件”);

$text=您看到的错误仅仅意味着您的php脚本没有打开testfile.rtf进行编写的权限。

无论何时遇到权限问题,都不要“chmod 777”任何内容,这可能会在以后引入安全问题!相反-为正确的用户提供正确的权限

在这种情况下:

由于您正在运行XAMPP,因此需要确保您的web服务器获得对您尝试在其中创建新文件和\或编辑现有文件的特定路径的写入权限

在OSX和apache的情况下,我相信Web服务器的用户名为“www”

下面是一个小例子(您可能需要根据自己的需要进行更改):

上面的示例将给出/path/to/文件夹及其所有文件的www(webserver)所有权

另外:在执行任何基于命令行的管理之前,您可能需要了解一些unix命令,例如chown、chmod等


希望对你有所帮助

你试过在你的主文件夹中运行这个吗?另外:文件是否确实存在?请相应地编辑你的问题。我写了sudo chown-R www:_www/Applications/XAMPP/xamppfiles/htdocs/test/testfile.rtf,但终端说:没有这样的文件或directory@JulienCorbin改为在文件夹(无文件名)上尝试
sudo chown -R _www:_www /path/to/folder