2010-01-08 108 views
0

這是用於上傳的PHP代碼:「該文件已成功上傳」上傳文件無法正常工作,此代碼有什麼問題?

$upload = "uploads/"; 
$upload = $upload . basename($_FILES['bgimage']['name']); 

if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) { 

    echo "The file has been uploaded successfully."; 

} else { echo "Error"; } 

當我測試腳本,它說但是當我查看FTP服務器,它不是真的...

另外,如果你需要知道,這裏的HTML代碼:

表單標籤:

<form name="profilestyle" action="account.php?action=profiletheme" method="post" enctype="multipart/form-data"> 

輸入標籤:

<input type="file" name="bgimage" /> 

額外的信息: 是的,我記得使用chmod的上傳目錄

回答

1

奇怪,代碼看起來很好,據我所知。

您可以使用file_exists()來檢查文件是否存在,但可能對您的FTP用戶不可見?

if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) { 

echo "The file '$upload' has been uploaded successfully."; 
if (file_exists($upload)) echo "And it exists! It is ".filesize($upload)." bytes big."; 
else echo "But it doesn't exist."; 

} else { echo "Error"; } 
0

請嘗試以下的測試代碼

$upload = "uploads/"; 
$upload = $upload . basename($_FILES['bgimage']['name']); 

sprintf('<pre>Debug: moving file from %s to %s</pre>', 
    $_FILES['bgimage']['tmp_name'], 
    $upload 
); 
if (move_uploaded_file($_FILES['bgimage']['tmp_name'], $upload)) { 
    echo "The file has been uploaded successfully."; 
    sprintf('<pre>Debug: realpath=%s, filesize=%d</pre>', 
    realpath($upload), 
    filesize($upload) 
); 
} 
else { 
    echo "Error"; 
} 

和ESP。密切關注realpath = xyz輸出。

1

您還需要檢查$_FILES['bgimage']['error']以確保它等於UPLOAD_ERR_OK並且不是錯誤代碼。

相關問題