2015-04-27 111 views
1

當在PHP中使用的move_uploaded_file()功能我得到的錯誤:給PHP的權限,而權限錯誤創建文件

Warning: move_uploaded_file(...): failed to open stream: Permission denied in ...

在我的服務器我有public_html權限,如:

drwxr-sr-x 7 user www-data 4096 Apr 27 17:48 public_html 

哪個遞歸地遍歷目錄。

你有什麼想法,爲什麼這可能不工作?或者我可以做些什麼來幫助我找出爲什麼這不起作用。


系統

服務器實際上是在文件上的NAS集羣和PHP是在集羣上。我正在執行NAS設備上的所有權限命令,因爲這是用戶FTP所在的位置。

+0

你沒有給錯誤的路徑,以便看看'upload_tmp_dir'和'sys_temp_dir'在php.ini或在附加INI文件。你真的上傳文件或只是想移動現有的文件嗎? – AbraCadaver

+0

'upload_tmp_dir'已被註釋掉(所以使用默認值)我是否需要創建它?當我'回聲sys_get_temp_dir();'我得到'/ tmp' – maxisme

+0

'sys_temp_dir'還沒有被發現在php.ini – maxisme

回答

0

用戶www-data無法寫入public_html目錄。使用您的public_html chmod命令給WWW的數據的寫入權限:

chmod 775 public_html -R 
+0

我可以發誓我已經嘗試了一百萬次!但它似乎奏效了。這是我第一次在實際的羣集上而不是NAS上做的......你認爲這與它有關嗎? – maxisme

0

首先,SUID和SGID在與可執行文件一起使用時纔有意義。

http://www.codecoffee.com/tipsforlinux/articles/028.html

SUID (Set User ID) Bit

[...] in case I have an application whose owner is ' root ' and it has its SUID bit set, then when I run this application as a normal user, that application would still run as root. Since the SUID bit tells Linux that the the User ID root is set for this application and whenever this application executes it must execute as if root was executing it (since root owns this file)

SGID (Set Group ID) bit

Just like SUID, setting the SGID bit for a file sets your group ID to the file's group while the file is executing. IT is really useful in case you have a real multi-user setup where users access each others files. As a single homeuser I haven't really found a lot of use for SGID. But the basic concept is the same as the SUID, the files whose SGID bit are set would be used as if they belong to that group rather than to that user alone.

所以,如果沒有你的web文件需要作爲一個正常的過程中執行,這是最好的獨自離開了SGID。

最後,如果你不改變你的Web服務器的安全上下文,它(最有可能,因爲你沒有提到任何路徑)試運行它位於一個目錄www-data只能文件。要移動文件,您需要寫入文件的目錄,並將其移動到。所以www-data應給予訪問

  1. ,其中擺在首位的文件土地的目錄(默認爲:/tmp,在這種情況下,沒有什麼是做)
  2. 目標目錄,它在哪裏打算搬到。