所以我决定将文件上传到Web服务器空间而不是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" />';
关于我做错什么的任何想法?
答案 0 :(得分:0)
警告:move_uploaded_file()[function.move-uploaded-file]:第240行/home/speedycm/public_html/manageclient.php中的文件名不能为空
这意味着$_FILES['userfile']['tmp_name']
中的任何内容实际上都是空的,或者不存在。在print_r
上运行var_dump
或$_FILES
,看看实际上是什么。你有可能在某处犯错。