我試圖通過HTML表單上傳文件(msword/doc)到Apache服務器文件夾。它在我本地測試(我通過MAMP測試它)時起作用,但是當我將它上傳到遠程服務器(如GoDaddy)時,它不起作用。它顯示「文件上傳存在問題」。PHP文件上傳(在本地工作,但不在遠程服務器上)。
以下是處理文件上傳的代碼片段。我無法弄清楚我的條件有什麼問題。任何想法,將不勝感激!
// Move the file to the target upload folder
$target = FILE_UPLOADPATH . basename($new_file);
if (move_uploaded_file($_FILES['new_file']['tmp_name'], $target))
{
// The new file move was successful, now make sure any old file is deleted
if (!empty($old_file) && ($old_file != $new_file))
{
@unlink(FILE_UPLOADPATH . $old_file);
}
}
else
{
// The new file move failed, so delete the temporary file and set the error flag
@unlink($_FILES['new_file']['tmp_name']);
echo 'There was a problem with the file upload.' . PHP_EOL;
}
您可以分享完整的$ _FILES數組,因爲錯誤參數中的值可能有助於闡明 – fullybaked 2013-04-29 16:05:56
這裏是$ _FILES數組輸出:Array([new_file] => Array([name] => sample .doc [type] => msword/doc [tmp_name] =>/tmp/phpsTu20P [error] => 0 [size] => 119674))想法? – kthaker 2013-04-29 16:25:15
錯誤參數中的值爲0. – kthaker 2013-04-29 16:28:25