2017-10-18 96 views
0

,我有以下的代碼段($settings是一些數據):的fopen:未能打開流:無效的參數

$file = fopen("D:\\this\\is\\the\\path.php", "w"); 
fwrite($file, $settings); 
fclose($file); 

而且我得到這個錯誤:

fopen(D:\this\is\the\path.php): failed to open stream: Invalid argument 
fwrite() expects parameter 1 to be resource, boolean given 
fclose() expects parameter 1 to be resource, boolean given 

我已經嘗試過修改路徑:

D:\this\is\the\path.php 
D:/this/is/the/path.php 

沒有任何作用,我敢肯定路徑是正確的,代碼是正確的! 奇怪,這是,它的工作原理(如果該文件不存在)與模式x(創建文件,並寫入)

但是如果文件存在,我不能因爲某些原因模式w覆蓋它。

我正在使用Windows系統。

我已經檢查了很多其他的答案,但我只是不起作用,即使我做了一切正確的其他答案。

+2

http://php.net/manual/en/function.fopen.php - '''成功返回文件指針資源,或FALSE的錯誤 您的腳本無法打開該文件進行寫入。 –

+0

爲什麼腳本無法使用?用戶擁有正確的權限..我100%確定路徑是正確的。如果我添加一個錯誤的路徑,它會說文件沒有找到 – modsfab

+0

它通常是權限,但我不能肯定地說。要驗證這是一個權限問題,你可以從你以「administrator身份運行」的shell運行你的腳本 –

回答

0

嘗試使用realpath,像這樣:

$file = fopen(realpath("D:\\this\\is\\the\\path.php"), "w"); 
相關問題