2011-05-14 103 views
0

我得到了一切,但這工作。我無法使move_uploaded_file();正常工作。php上傳文件

$ups_path = "ups/files"; 
$nfile = $_FILES['nfile']['tmp_name']; 
$cfile = move_uploaded_file($nfile, $ups_path); 

if($cfile){ 
header ('Location: index.php?give=fileuploaded'); 
} else { 
header ('Location: index.php?give=filenotuploaded'); 
} 

它總是返回不移動它的錯誤。

+0

'$ ups_path'應該是絕對的。 – Orbling 2011-05-14 13:28:22

+2

*你得到了什麼*錯誤?注意,'mysql_real_escape_string()'在這一點上沒有用處。它不會刪除文件名中的非法字符。 – 2011-05-14 13:28:24

+0

爲什麼在'tmp_name'上使用'mysql_real_escape_string'?可能你正在改變絃樂。檢查是否是這種情況。 – 2011-05-14 13:33:47

回答

1

如果UPS /文件的目錄,那麼這將失敗。 move_uploaded_file期望第二個參數是文件名,而不是目錄。

+0

謝謝!接得好。我忘了讓它像'$ ups_path =「ups/files/$ date_ $ filename」;'。我的腳本現在正在完成:) – yanike 2011-05-14 14:27:18

0

嘗試使用絕對路徑,而不是相對之一:

$ups_path = "/var/www/somewhere/ups/files";