亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Warning: in_array() expects parameter 2 to be array, boolean given in

https://img1.sycdn.imooc.com//5cda55280001b21e15060249.jpg

已經var_dump($allowExt)確實是個數組,為什么還出現上面錯誤?


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必選參數?*?@param?array?$allowExt?*?@param?unknown?$maxsize?*?@param?string?$path?*?@param?string?$flag是否開啟圖片真實性檢測?*/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?=?"上傳的文件超過了?php.ini?中?upload_max_filesize?選項限制的值。?";????????????????break;????????????case?2:????????????????$mes?=?"上傳文件的大小超過了?HTML?表單中?MAX_FILE_SIZE?選項指定的值。?";????????????????break;????????????case?3:????????????????$mes?=?"文件只有部分被上傳?";????????????????break;????????????case?4:????????????????$mes?=?"沒有文件被上傳?";????????????????break;????????????case?6:????????????????$mes?=?"找不到臨時文件夾。?";????????????????break;????????????case?7:????????????case?8:????????????????$mes?=?"系統錯誤";????????????????break;????????}????????exit($mes);????}????//?檢測上傳文件的類型????$ext?=?pathinfo($fileInfo['name'])['extension'];????/*?????*?$allowExt?=?[?????*?'jpeg',?????*?'jpg',?????*?'gif',?????*?'png',?????*?'wbmp',?????*?'rar'?????*?];?????*/????if?(!in_array($ext,?$allowExt))?{????????exit("非法文件類型");????}????//?檢測是不是真實的圖片文件????//?$flag?=?true;????if?($flag)?{????????if?(@!?getimagesize($fileInfo['tmp_name']))?{????????????exit("上傳的不是真實的圖片文件");????????}????}????//?檢測文件大小????//?$maxsize?=?1?*?1024?*?1024;????if?($fileInfo['size']?>?$maxsize)?{????????exit("上傳文件太大!");????}????//?檢測文件是不是是通過HTTP_POST方式上傳的????if?(!?is_uploaded_file($fileInfo['tmp_name']))?{????????exit("文件不是通過httppost方式上傳的");????}????//?移動文件????//?$path?=?"uploads";????//?如果目錄不存在創建目錄????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);


正在回答

1 回答

找到原因了,函數調用的時候參數順序搞錯了,導致的問題

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

Warning: in_array() expects parameter 2 to be array, boolean given in

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號