开发者

trying out new file upload method

开发者 https://www.devze.com 2022-12-21 20:06 出处:网络
so i\'ve decided to upload the files onto the web server space rather than the mysql space but each time i try to upload anything i get the following error:

so i've decided to upload the files onto the web server space rather than the mysql space but each time i try to upload anything i get the following error:

    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

this is the code im using:

 <?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" /&g开发者_JAVA百科t;';

any ideas as to what i am doing wrong?


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

This means that whatever is coming through in $_FILES['userfile']['tmp_name'] is actually empty, or doesn't exist. Run print_r or var_dump on $_FILES to see what's actually there. Chances are you have a typo somewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消