我在我的上傳文件中有這個錯誤。語法是正確的,問題在哪裏?is_uploaded_file array給出錯誤
錯誤:
is_uploaded_file() expects parameter 1 to be string, array given in C:\Program Files\EasyPHP-5.3.5.0\www\bena_website\admin\variables\upload_img.php on line 34
<h3>Please Choose a File and click Submit</h3>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input name="userfile[]" type="file" />
<input type="submit" value="Submit" />
</form>
<?php
// check if a file was submitted
if(!isset($_FILES['userfile'])) {
echo '<p>Please select a file</p>';
}
else
{
print_r($_FILES);
try {
upload();
// give praise and thanks to the php gods
echo '<p>Thank you for submitting</p>';
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
// the upload function
function upload(){
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {
// check the file is less than the maximum file size
if($_FILES['userfile']['size'] < $maxsize)
{
// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
// $imgData = addslashes($_FILES['userfile']);
// get the image info..
$size = getimagesize($_FILES['userfile']['tmp_name']);
// put the image in the db...
// database connection
mysql_connect("localhost", "root", "") OR DIE (mysql_error());
// select the db
mysql_select_db ("bena") OR DIE ("Unable to select db".mysql_error());
// our sql query
$sql = "INSERT INTO testblob
(image_id , image_type ,image, image_size, image_name)
VALUES
('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";
// insert the image
if(!mysql_query($sql)) {
echo 'Unable to upload file';
}
}
}
else {
// if the file is not less than the maximum allowed, print an error
echo
'<div>File exceeds the Maximum File limit</div>
<div>Maximum File limit is '.$maxsize.'</div>
<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div>
<hr />';
}
}
?>
你能顯示你的HTML表單嗎? – 2011-05-01 15:39:50
我想你有多個文件輸入那裏或1與名稱用戶文件** [] ** – 2011-05-01 15:41:15
我有一種感覺佩卡認爲是一樣的,但我認爲你張貼多個文件在你的窗體?在這種情況下,'$ _FILES ['userfile'] ['tmp_name']'將保存一組路徑。再想一想,你的變量名稱('userfile')看起來像只上傳一個文件。在這種情況下,請'print_r()'$ _FILES'數組並將其添加到您的問題:-) – Bojangles 2011-05-01 15:41:38