我使用Ubuntu作爲我的操作系統,並且我有XAMPP。在htdocs
文件夾中,我創建了一個項目文件夾,其中有index.php
文件。現在的index.php,代碼的一部分,做到這一點:在Ubuntu中運行PHP程序 - fopen(「filename」,「w」):無法打開流:權限被拒絕
fopen("colors_new.csv", "w");
從manual,
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
但該文件,而不是被創建的,我越來越
Warning: fopen(colors_new.csv): failed to open stream: Permission denied...
而當我查看項目文件夾時,colors_new.csv
文件未創建。
當我在運行Windows操作系統的另一臺計算機上運行此程序時,它運行成功。該文件已成功創建。
如何解決Ubuntu中的這個問題?
我的嘗試:
我試圖運行sudo chmod 777 colors_new.csv
,但我得到chmod: can not access colors_new.csv. No such file or directory.
。我試着用文件名(如圖所示)在項目目錄中的WAS終端上執行此操作;以及提供文件的完整絕對路徑。兩次都有同樣的錯誤。
注:我所看到的其他問題,如上面所指出的,我想給權限的文件。其他問題沒有解決問題,下面接受的答案確實解決了這個問題。
在運行chmod命令之前,您必須在文件的位置。否則它會拋出錯誤:chmod:無法訪問colors_new.csv。沒有這樣的文件或目錄 –
這個問題不在文件中,因爲它沒有被創建,但是使用文件夾/目錄,你很可能沒有在目錄/文件夾中創建文件的權限 – Epodax
可能有[無法打開流:沒有這樣的文件或目錄](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) –