2016-03-08 127 views
0

我試圖通過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

回答

1

有很多原因可能導致您的PHP腳本無法寫入文件系統。最常見的是權限問題:Web服務器運行的用戶沒有寫入相關目錄的權限。

您可能無法寫入文件的另一個原因是,根據我的經驗,某些服務提供商使用disable_functions指令禁用php.ini文件中的文件I/O功能。你必須讓服務器的管理員爲你改變這個。

+0

我個人感覺到相同的權限問題,如果你指定可以使用full – Shaik

相關問題