我正在尝试通过 php 在新的生产服务器中向 txt 文件添加文本,如果在我的本地机器上尝试发生同样的事情,并且我已经授予了对服务器中文件夹的所有权限,尽管这并没有保存这个声音很有趣我尝试了谷歌说仍然不起作用的所有可能方式
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file! " . var_export(error_get_last(), true));
$txt = "Mickey Mouse'n";
fwrite($myfile, $txt);
$txt = "Minnie Mouse'n";
fwrite($myfile, $txt);
fclose($myfile);
?>
目录中的输出错误
PHP Warning: fopen(newfile.txt): failed to open stream: Permission denied in C:'Inetpub'vhosts'test.in'httpdocs'Test.php on line 2
不同驱动器的错误
PHP Warning: fopen(): open_basedir restriction in effect. File(E:'Log
ewfile.txt) is not within the allowed path(s): (C:/Inetpub/vhosts/test.in';C:'Windows'Temp') in C:'Inetpub'vhosts'test.in'httpdocs'Test.php on line 2
PHP Warning: fopen(E:'Log
ewfile.txt): failed to open stream: Operation not permitted in C:'Inetpub'vhosts'test.in'httpdocs'Test.php on line 2
PHP 脚本可能无法写入文件系统的原因有很多。最常见的问题是权限问题:运行 Web 服务器的用户无权写入相关目录。
您可能无法写入文件的另一个原因是,根据我的经验,某些服务提供商使用 disable_functions 指令禁用php.ini
文件中的文件 I/O 功能。您必须让服务器的管理员为您更改此设置。