PHP不写文本到txt文件的Windows服务器2012 R2

问题描述:

我试图通过PHP文本添加到新的生产服务器不插入,如果同样我尝试在我的本地机器上发生,我已经给予所有权限在服务器,虽然该文件夹中不保存这个声音逗我想,谷歌表示,仍然是所有可能的方式不是在目录中工作PHP不写文本到txt文件的Windows服务器2012 R2

<?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 
+2

只是澄清:代码运行到'或死(“无法打开文件!”)'“条件”? – VolkerK

+0

@VolkerK是的正确,但我的观点是如何给php一个文件写入文件的访问 – Shaik

+0

为了调试的目的:你可以使用'或者死(“无法打开文件!”)。var_export(error_get_last(),true)) ;'和[add](http://stackoverflow.com/posts/35865591/edit)输出到你的问题文本? (也许编辑实际的路径,如果你觉得它显示到你的服务器的大部分) – VolkerK

有很多原因可能导致您的PHP脚本无法写入文件系统。最常见的是权限问题:Web服务器运行的用户没有写入相关目录的权限。

您可能无法写入文件的另一个原因是,根据我的经验,某些服务提供商使用disable_functions指令禁用php.ini文件中的文件I/O功能。你必须让服务器的管理员为你改变这个。

+0

我个人感觉到相同的权限问题,如果你指定可以使用full – Shaik