所以我決定將文件上傳至網絡服務器空間,而不是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> ' . $fileName . '<p><i><u>Size:</u> ' . $fileSize . 'k' . '<p><u>Type:</u> ' . $fileType . '</i><i><u>Path:</u> ' . $filePath. '<p><p><p><img src="resources/spacer.gif" alt="" width="300px" height="5px" />';
任何想法,我在做什麼錯?
權限。 ... – Layke 2010-03-02 00:20:18
如果它不是Laykes可能建議的許可問題,請檢查'tmpName'的'var_dump'?您可以更好地瞭解您正在處理的內容。就個人而言,我總是在傾倒後放心。 – 2010-03-02 00:22:16
錯誤消息清楚地表明它不是權限問題。 – Franz 2010-03-02 00:24:02