Warning: in_array() expects parameter 2 to be array, boolean given in
已經(jīng)var_dump($allowExt)確實(shí)是個(gè)數(shù)組,為什么還出現(xiàn)上面錯(cuò)誤?
upload.html:
<!DOCTYPE?html><html><head><meta?charset="UTF-8"><title>Insert?title?here</title></head><body><!--?The?data?encoding?type,?enctype,?MUST?be?specified?as?below?--><form?enctype="multipart/form-data"?action="doAction3.php"?method="POST">????<!--?MAX_FILE_SIZE?must?precede?the?file?input?field?-->????<input?type="hidden"?name="MAX_FILE_SIZE"?value="3000000"?/>????<!--?Name?of?input?element?determines?name?in?$_FILES?array?-->????選擇文件:?<input?name="userfile"?type="file"?/>????<input?type="submit"?value="上傳"?/></form></body></html>
upload.function.php:
<?php/*?*?$filename?=?$_FILES['userfile']['name'];?*?$filetype?=?$_FILES['userfile']['type'];?*?$filetmp_name?=?$_FILES['userfile']['tmp_name'];?*?$filesize?=?$_FILES['userfile']['size'];?*?$fileerror?=?$_FILES['userfile']['error'];?*/?$fileInfo?=?$_FILES['userfile'];/***?*?*?@param?unknown?$fileInfo必選參數(shù)?*?@param?array?$allowExt?*?@param?unknown?$maxsize?*?@param?string?$path?*?@param?string?$flag是否開(kāi)啟圖片真實(shí)性檢測(cè)?*/function?uploadFile($fileInfo,?$allowExt?=?['jpg','jpeg','gif','png','zip'],?$maxsize?=?1?*?1024?*?1024,?$path?=?"uploads",?$flag?=?true){????if?($fileInfo['error']?>?0)?{????????switch?($fileInfo['error'])?{????????????case?1:????????????????$mes?=?"上傳的文件超過(guò)了?php.ini?中?upload_max_filesize?選項(xiàng)限制的值。?";????????????????break;????????????case?2:????????????????$mes?=?"上傳文件的大小超過(guò)了?HTML?表單中?MAX_FILE_SIZE?選項(xiàng)指定的值。?";????????????????break;????????????case?3:????????????????$mes?=?"文件只有部分被上傳?";????????????????break;????????????case?4:????????????????$mes?=?"沒(méi)有文件被上傳?";????????????????break;????????????case?6:????????????????$mes?=?"找不到臨時(shí)文件夾。?";????????????????break;????????????case?7:????????????case?8:????????????????$mes?=?"系統(tǒng)錯(cuò)誤";????????????????break;????????}????????exit($mes);????}????//?檢測(cè)上傳文件的類(lèi)型????$ext?=?pathinfo($fileInfo['name'])['extension'];????/*?????*?$allowExt?=?[?????*?'jpeg',?????*?'jpg',?????*?'gif',?????*?'png',?????*?'wbmp',?????*?'rar'?????*?];?????*/????if?(!in_array($ext,?$allowExt))?{????????exit("非法文件類(lèi)型");????}????//?檢測(cè)是不是真實(shí)的圖片文件????//?$flag?=?true;????if?($flag)?{????????if?(@!?getimagesize($fileInfo['tmp_name']))?{????????????exit("上傳的不是真實(shí)的圖片文件");????????}????}????//?檢測(cè)文件大小????//?$maxsize?=?1?*?1024?*?1024;????if?($fileInfo['size']?>?$maxsize)?{????????exit("上傳文件太大!");????}????//?檢測(cè)文件是不是是通過(guò)HTTP_POST方式上傳的????if?(!?is_uploaded_file($fileInfo['tmp_name']))?{????????exit("文件不是通過(guò)httppost方式上傳的");????}????//?移動(dòng)文件????//?$path?=?"uploads";????//?如果目錄不存在創(chuàng)建目錄????if?(!?file_exists($path))?{????????mkdir($path,?0777,?true);????????chmod($path,?0777);????}????//?防止文件重名覆蓋????$uniName?=?md5(uniqid(microtime(true),?true))?.?'.'?.?$ext;????$destination?=?$path?.?'/'?.?$uniName;????if?(!?move_uploaded_file($fileInfo['tmp_name'],?$destination))?{????????echo?"文件上傳失敗";????}?else?{????????return?$destination;????}}
doAction3.php:
<?phpinclude_once?'upload.function.php';$fileInfo?=?$_FILES['userfile'];$allowExt?=?['jpg','jpeg','gif','png','zip'];$maxsize?=?1?*?1024?*?1024;$path?=?"uploads";$flag?=?false;//?var_dump($allowExt,$flag,$maxsize);die();$newName?=?uploadFile($fileInfo,$flag,$allowExt);//?var_dump($newName);
2019-05-14
找到原因了,函數(shù)調(diào)用的時(shí)候參數(shù)順序搞錯(cuò)了,導(dǎo)致的問(wèn)題