2010-03-02 54 views
2

所以我決定將文件上傳至網絡服務器空間,而不是MySQL的空間,但每一次我嘗試上傳任何我得到以下錯誤:嘗試新的文件上傳方法

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home/speedycm/public_html/manageclient.php on line 240 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpq7cUA4' to '' in /home/speedycm/public_html/manageclient.php on line 240 
Error uploading file 

這是代碼即時通訊使用:

<?php 
       if (array_key_exists('uploadfile',$_POST)) { 

$uploadDir = '/upload'; 

$fileName = $_FILES['userfile']['name']; 
$tmpName = $_FILES['userfile']['tmp_name']; 
$fileSize = $_FILES['userfile']['size']; 
$fileType = $_FILES['userfile']['type']; 
$filePath = $uploadDir . $fileName; 

// get the file extension first 
$ext = substr(strrchr($fileName, "."), 1); 

// make the random file name 
$randName = md5(rand() * time()); 

// and now we have the unique file name for the upload file 
$filePath = $uploadDir . $randName . '.' . $ext; 

$result = move_uploaded_file($tmpName, $filePath); 
if (!$result) { 
echo "Error uploading file"; 
exit; 
} 

if(!get_magic_quotes_gpc()) 
{ 
$fileName = addslashes($fileName); 
$content = addslashes($filePath); 
} 

mysql_query("INSERT INTO tbl_accidentfiles (`client_id`,`name`,`type`,`size`,`path`) 
VALUES ('$client_id', '$fileName', '$fileType', '$fileSize','$filePath')"); 

echo '<b>File Upload</b><p>Thank you. The file has been successfully uploaded. 

<p><img src="resources/spacer.gif" alt="" width="300px" height="5px" /><p><o> 

<i><u>Name:</u>&nbsp;' . $fileName . '<p><i><u>Size:</u>&nbsp;' . $fileSize . 'k' . '<p><u>Type:</u>&nbsp;' . $fileType . '</i><i><u>Path:</u>&nbsp;' . $filePath. '<p><p><p><img src="resources/spacer.gif" alt="" width="300px" height="5px" />'; 

任何想法,我在做什麼錯?

+0

權限。 ... – Layke 2010-03-02 00:20:18

+1

如果它不是Laykes可能建議的許可問題,請檢查'tmpName'的'var_dump'?您可以更好地瞭解您正在處理的內容。就個人而言,我總是在傾倒後放心。 – 2010-03-02 00:22:16

+2

錯誤消息清楚地表明它不是權限問題。 – Franz 2010-03-02 00:24:02

回答

0

Warning: move_uploaded_file() [function.move-uploaded-file]: Filename cannot be empty in /home/speedycm/public_html/manageclient.php on line 240

這意味着,無論是在$_FILES['userfile']['tmp_name']未來通過實際上是空的,或者不存在。在$_FILES上運行print_rvar_dump以查看實際存在的內容。機會是你有一個錯字。

+0

這是一個目錄問題,OP解決了它。 – 2010-03-02 00:28:01

相關問題