我明明用的是老師的代碼,但是運(yùn)行的時(shí)候就是一直報(bào)錯(cuò)。請(qǐng)問這是為什么???
function?uploadFile($fileInfo,$path='./uploads',$flag=true,$maxSize=1048576,$allowExt=array('jpeg','jpg','png','gif')){
???//$flag=true;
???//$allowExt=array('jpeg','jpg','gif','png');
???//$maxSize=1048576;//1M
???//判斷錯(cuò)誤號(hào)
???if($fileInfo['error']===UPLOAD_ERR_OK){
??????//檢測(cè)上傳得到小
??????if($fileInfo['size']>$maxSize){
?????????$res['mes']=$fileInfo['name'].'上傳文件過大';
??????}
??????$ext=getExt($fileInfo['name']);
??????//檢測(cè)上傳文件的文件類型
??????if(!in_array($ext,$allowExt)){
?????????$res['mes']=$fileInfo['name'].'非法文件類型';
??????}
??????//檢測(cè)是否是真實(shí)的圖片類型
??????if($flag){
?????????if(!getimagesize($fileInfo['tmp_name'])){
????????????$res['mes']=$fileInfo['name'].'不是真實(shí)圖片類型';
?????????}
??????}
??????//檢測(cè)文件是否是通過HTTP?POST上傳上來的
??????if(!is_uploaded_file($fileInfo['tmp_name'])){
?????????$res['mes']=$fileInfo['name'].'文件不是通過HTTP?POST方式上傳上來的';
??????}
??????if($res)?return?$res;
??????//$path='./uploads';
??????if(!file_exists($path)){
?????????mkdir($path,0777,true);
?????????chmod($path,0777);
??????}
??????$uniName=getUniName();
??????$destination=$path.'/'.$uniName.'.'.$ext;
??????if(!move_uploaded_file($fileInfo['tmp_name'],$destination)){
?????????$res['mes']=$fileInfo['name'].'文件移動(dòng)失敗';
??????}
??????$res['mes']=$fileInfo['name'].'上傳成功';
??????$res['dest']=$destination;
??????return?$res;
2019-09-01