2017-08-15 224 views
1

我需要幫助解決這個錯誤:Laravel地方:FOPEN權限被拒絕

fopen(/Subckt.txt): failed to open stream: Permission denied

  • 我使用Laravel
  • 我工作的網站在本地使用CMD與PHP 工匠服務命令
  • 我發現了一些與chmod的潛在解決方案,但由於我使用本地主機,我不認爲它的工作
  • 該網站正在運行一個PHP代碼來修改一個txt文件。然後我將它保存到另一個文件。在根文件夾中。
  • 整個網站文件夾被聲明爲只讀,我無法修改該文件夾。 (我使用Windows 7,當我取消選中它總是重新檢查框,但我設法刪除只讀文本文件(Subckt.txt和\ npn.lib)
  • 我試着我的代碼沒有laravel在。PHP和HTML文件,它的工作原理

這裏是我的部分代碼:。

// Load the output file 
$outputFile = fopen("\Subckt.txt", "w") or die("Unable to open file!"); 

// Load the input file into string 
$inputFile = "\npn.lib"; 

// Put the input file in a string variable 
$inputFileContent = file_get_contents($inputFile); 
+1

檢查你的'基路徑'。 'fopen'函數似乎試圖從文件系統的根目錄加載文件,這肯定會產生權限衝突。 – Ohgodwhy

+0

In:$ inputFile =「\ npn.lib」; \ n被認爲是新行... – Mark

+0

$ inputFileContent = file_get_contents(「C:\ Users \ username \ Desktop \ model \\ testnpn.lib」);而不是2行 – Mark

回答

0

你有上運行PHP腳本的用戶文件的寫權限?誰在試圖在fopen的文件屬於?也許這是www-data用戶試圖運行試圖打開該文件的php腳本,但是如果文件不是由www-data組擁有的,或者沒有全局寫入權限,它將與php的權限衝突。如果你在linux上,試試用這個chown -R www-data:www-data /path/to/the/project/folder。如果chown方法不起作用,請嘗試使用chmod -R 775 /path/to/the/file。在窗戶上,我不知道...我希望我可以幫助一些。