我試圖使用PHP上傳文件,代碼snipptPHP move_uploaded_file forcely賦予了新的名字
$upload_path = "/var/upload/" . $_FILES['mfile']['name'];
if(move_uploaded_file($_FILES['mfile']['tmp_name'], $upload_path))
echo "file uploaded";
else
echo "upload failed";
注意:在/ var/upload目錄存在並且具有777權限。
的代碼打印 「上傳失敗」
當我檢查/ var/upload目錄,有文件f_505bf77bd8a0f_mypdf.pdf。什麼地方出了錯?
添加日誌(按照由loler要求):
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined variable: showdebug in /Volumes/data/htdocs/ebeu/upload.php on line 558, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined variable: showdebug in /Volumes/data/htdocs/ebeu/upload.php on line 559, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: accessories in /var/www/my/web/folder/myupload.php on line 21, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: pmaterial in /var/www/my/web/folder/myupload.php on line 27, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: occupation_bwc in /var/www/my/web/folder/myupload.php on line 33, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: occupation_bwc in /var/www/my/web/folder/myupload.php on line 75, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: occupation_spec in /var/www/my/web/folder/myupload.php on line 75, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined index: babycarrier in /var/www/my/web/folder/myupload.php on line 78, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined variable: accessories_all in /var/www/my/web/folder/myupload.php on line 79, referer: http://localhost/upload/test/upload.php
[Fri Sep 21 10:58:31 2012] [error] [client ::1] PHP Notice: Undefined variable: pmaterials_all in /var/www/my/web/folder/myupload.php on line 80, referer: http://localhost/upload/test/upload.php
新增的var_dump($ _ FILES)
array(1) {
["mfile"]=>
array(5) {
["name"]=>
string(23) "mypdf.pdf"
["type"]=>
string(15) "application/pdf"
["tmp_name"]=>
string(26) "/var/tmp/phpUl6k50"
["error"]=>
int(0)
["size"]=>
int(478704)
}
}
什麼是你的['upload_tmp_dir'](http://us.php.net/manual/en/ini.core.php#ini.upload- TMP-DIR)?你確定你看到的這個文件與你的上傳有關,而不是來自其他地方? (如果您信任用戶提供的文件名太多,您最終會覆蓋現有文件。) – DCoder
您可以檢查Apache錯誤日誌嗎? – F0G
DCoder,我是110%;-)確實如此。因爲我刪除目錄中的所有文件並嘗試腳本。我甚至驗證了文件打開目錄。 – Elisa