2011-10-16 59 views
1

你好我想通過表單上傳到我的服務器上的文件,用戶選擇在本地計算機上,但我得到了下面的PHP錯誤:move_uploaded_file PHP錯誤

Warning: move_uploaded_file(bqformtest/uploaded_files/test.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/drawapl1/public_html/bqformtest/index.php on line 40

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphhS4QD' to 'bqformtest/uploaded_files/test.doc' in /home/drawapl1/public_html/bqformtest/index.php on line 40

這是我的PHP代碼:

  $target = "bqformtest/uploaded_files/"; 
     $target = $target . basename($_FILES['upload']['name']) ; 
     if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) 
     { 
     echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded"; 
     } 
     else { 
     echo "Sorry, there was a problem uploading your file."; 
     } 

這是我的表單代碼:

<form method='post' action='' accept-charset='UTF-8' enctype='multipart/form-data'> 
<input type="file" name="upload" size="50" /> 
<input id="submitButton" type='submit' name='Submit' value='' /> 
</form> 

的uploaded_files文件夾的權限設置爲755。謝謝提前。

+0

uploaded_files dir的所有者是什麼? – xdazz

回答

1

提供完整的文件路徑,或右相對路徑

$target = "{fullPath}/fileName"; 

的路徑,文件是錯誤的

+1

如果我將此行代碼中的路徑更改爲'$ target =「home/drawapl1/www/bqformtest/uploaded_files /」;'我收到相同的錯誤消息。我認爲這是完整的道路。 –

+1

@Ben Paton:完整路徑必須以'/'開頭 –

+0

謝謝你剛剛錯過了開始/ :) –

0

從我可以根據錯誤信息告知,你的腳本是ROOT/bqformtest。然後您將$target設置爲相對路徑:bqformtest/uploaded_files。這意味着腳本會嘗試將上傳的文件從臨時目錄移至:ROOT/bqformtest + bqformtest/uploaded_files導致:ROOT/bqformtest/bqformtest/uploaded_files。設置$target到:

$target = "uploaded_files/"; 

$target = "/home/drawapl1/public_html/bqformtest/uploaded_files/"; 

,它應該工作。

順便說一下,您正在使用上傳文件的名稱,而不進行消毒,這是一個主要的安全風險。不要相信用戶發送的任何內容。

0

另請檢查用戶的磁盤配額。我遇到了這個問題,經過幾個小時的測試後,我發現它很簡單。超過用戶的配額