2012-01-30 39 views
0

我想從php表單上傳文件。 我已經驗證了目標位置與我的ISP爲 「/家庭/ hulamyxr /的public_html/POD /」PHP將文件從表單上傳到Web服務器。錯誤消息

執行頁面時,我得到了以下錯誤:

Warning: move_uploaded_file(/home/hulamyxr/public_html/POD/ 1511.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/hulamyxr/public_html/hauliers/include/capturelocal2.php on line 124 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpyp3ERS' to '/home/hulamyxr/public_html/POD/ 1511.pdf' in /home/hulamyxr/public_html/hauliers/include/capturelocal2.php on line 124 
POD Successfully uploaded for delivery 1511. filename: : 

我的表單代碼

<form enctype="multipart/form-data" method="post" action="capturelocal2.php"> 
<input type=file size=6 name=ref1pod id=ref1pod> 
</form> 

我的PHP代碼上傳的文件

$ref1 = $_POST[ref1]; //this is the name I want the file to be 
$ref1pod = $_POST[ref1pod]; // this is the name of the input field in the form 

    move_uploaded_file($_FILES["ref1pod"]["tmp_name"], 
    "/home/hulamyxr/public_html/POD/ " . ($ref1.".pdf")); 

任何援助將是格雷亞tly讚賞。 感謝和問候, 萊恩史密斯

+1

是否'POD'目錄存在,它是由PHP腳本寫嗎?你可以使用['is_dir()'](http://php.net/manual/en/function.is-dir.php)和['is_writable()'](http://www.php.net/ manual/en/function.is-writable.php)來檢查。另外,爲什麼'POD /'和目標文件之間的空間?如果沒有至少某種形式的驗證,你真的不應該允許用戶選擇一個文件名 – Phil 2012-01-30 04:51:38

回答

3

。在你的代碼中的錯誤:

你需要改變你的move_uploaded_file函數。有一個額外的空間,我認爲這是造成問題:

move_uploaded_file($_FILES["ref1pod"]["tmp_name"],"/home/hulamyxr/public_html/POD/" .($ref1.".pdf")); 

而且我不知道哪裏是

$ref1 = $_POST[ref1]; //this is the name I want the file to be 
$ref1pod = $_POST[ref1pod]; 

從未來。有在你的表格沒有這樣的價值觀。您是否僅上傳僅帶上傳的表單?另外請確保在表單和帖子值中加上引號。

是ref1和ref1pod是常量。如果你不加引號PHP將把它作爲常量。如果他們不是常量更改爲:

$ref1 = $_POST['ref1']; //this is the name I want the file to be 
$ref1pod = $_POST['ref1pod']; 

此外,在您的形式,把報價:

<form enctype="multipart/form-data" method="post" action="capturelocal2.php"> 
    <input type="file" size="6" name="ref1pod" id="ref1pod"/> 
</form> 

確保您設置權限,上傳的文件夾。

希望這有助於你:)

1

檢查文件夾名稱,他們應該是區分大小寫,並檢查是否POD文件夾有777個權限(CHMOD)

1

同意菲爾,刪除空格的字符串和文件名之間

"/home/hulamyxr/public_html/POD/ " . ($ref1.".pdf")); 
           ^
           | 

,你也可以嘗試以下方法:

$ref1 = $_POST[ref1]; 
$file_name = $_SERVER['DOCUMENT_ROOT'] . '/POD/' . $ref1 . '.pdf'; 
move_uploaded_file($_FILES['ref1pod']['tmp_name'], $file_name); 
1

請嘗試以下代碼。

<?php 
if(isset($_REQUEST['upload'])) { 
    $filename = $_FILES['ref1pod']['tmp_name']; 
    if (file_exists($_SERVER['DOCUMENT_ROOT']."/POD/".$_FILES["ref1pod"]["name"])) 
     { 
     echo $_FILES["ref1pod"]["name"] . " Already Exists. "; 
     } 
     else { 
    $path = $_SERVER['DOCUMENT_ROOT']."/POD/".$_FILES['ref1pod']['name']; 
     move_uploaded_file($filename,$path);   
    } 
} 
?> 

<form enctype="multipart/form-data" method="post" action=""> 
<input type=file size=6 name=ref1pod id=ref1pod> 
<input type="submit" name="upload" value="upload" /> 
</form> 

http://patelmilap.wordpress.com/2012/01/30/php-file-upload/