我有PHP腳本(testupload.php):PHP move_uploaded_file()以發行
<?php
error_reporting(E_ALL);
ini_set('log_errors',1);
ini_set('error_log','/root/work/inputs/log_file');
$target_path = "/work/inputs";
$target_path = $target_path . basename($_FILES['frag3']['name']);
echo "Received File: " . $_FILES['frag3']['name'] . " and moving it to " . $target_path . "<br>";
if(move_uploaded_file($_FILES['frag3']['name'], $target_path)) {
echo "The file ". basename($_FILES['frag3']['name']) . " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
和HTML文件來調用它:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form action = "http://localhost:8081/testupload.php" method="post" enctype="multipart/form-data">
<span>Value : </span><input type="text" name="Value" value="Hello world"/><br />
<span>Fragment File : </span><input type="file" name="frag3" /><br />
<input type="submit" value="Send"/>
</form>
</body>
</html>
不過,我不斷收到響應: There was an error uploading the file, please try again!
所以很明顯,move_uploaded_file()
是不正確的功能。另外,它並不實際移動文件。但是,我似乎無法診斷問題。
我首先想到的是,目錄無法寫入。但我的文件夾的權限是drwxrwxrwx
(如通過ls -l
確定)
此外,線: 函數ini_set( '的error_log', '/根/工作/輸入/ LOG_FILE');
似乎並沒有寫日誌文件到該位置。
有沒有人有這方面的經驗?我如何診斷這裏發生了什麼?
我幾乎在這裏的損失,所以任何幫助將不勝感激。
我使用的OpenSUSE 11.2,Apache 2.2的,和PHP 5.3。
非常感謝, 佈雷特
$ _FILES ['frag3'] ['tmp_name']的值似乎爲空。爲什麼會這樣?雖然有$ _FILES ['frag3'] ['name']的值(這就是爲什麼我 - 不正確 - 使用它)。有什麼想法嗎? – Brett
你最好先檢查'$ _FILES ['frag3'] ['error']',錯誤代碼定義在這裏http://www.php.net/manual/en/features.file-upload.errors .php – xdazz
我就是這麼做的!這是一個文件大小限制。但我也將所有內容都更改爲tmp_name,這樣有幫助。猜猜我有兩個問題!謝謝你的幫助!!! – Brett