<?php?
function?_upload($fileinfo,
????$ext=pathinfo($file['name'],
????PATHINFO_EXTENSION),
????$select_ext=array('jpg','jpeg','mp4','png','gif'),
????$max=1048576,
????$path='uploads',
????$flase=true,
????$hid=md5(uniqid(microtime(true),true)),
????$destination=$path.'/'.$hid.'.'.$ext)
????{
????if?($file['error']>0)?{
????switch?($file['error'])?{
????case?1:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_ini_size?錯(cuò)誤號(hào)為1?文件超過(guò)了php.ini?中?upload_max_filesize?限制的值';
????????break;
????case?2:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_form_size?錯(cuò)誤號(hào)為2?文件超過(guò)了html表單中max_file_size?限制的值';
????????break;
????case?3:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_partial?其值為3?只有部分文件被上傳';
????????break;
????case?4:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_no_file?其值為4,沒(méi)有文件被上傳';
????????break;
????case?6:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_no_tmp_dir?其值為6,找不到臨時(shí)文件';
????????break;
????case?7:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_cant_write?其值為7,文件寫(xiě)入失敗';
????????break;
????case?8:
????$ess='有錯(cuò)誤發(fā)生!?upload_err_extension?其值為8,上傳文件被PHP擴(kuò)展程序中斷';
????}
????exit($ess);
????}
????//判斷上傳的擴(kuò)展名是否為一個(gè)數(shù)組
????if?(!is_array($select_ext))?{
????????exit('非法擴(kuò)展名');
????}
????//判斷后綴是否符合要求
????if?(!in_array($ext,$select_ext))?{
????????exit('上傳格式不符合規(guī)定,請(qǐng)上傳jpg,png,gif,mp4類(lèi)型文件');
????}
????//判斷是否為真實(shí)的圖片文件
????if($flase){
????if(!getimagesize($file['tmp_name'])){
????????exit('文件非法!');
????}
????}
????//限制文件大小
????if?($file['siez']>$max)?{
????????exit('文件不能超過(guò)2M');
????}//如果不存在文件夾,則創(chuàng)建
????if(!file_exists($path)){
????????mkdir($path,0777,true);
????????chmod($paht,0777);
????}
????if?(move_uploaded_file($file['tmp_name'],$destination))?{
????????exit('文件'.$destination.'上傳成功!');
????}else{
????????exit('文件'.$destination.'上傳失?。?);
????}
????return?$destination;
}
?>
2019-05-06
找到答案了,給函數(shù)傳參數(shù)不能傳遞哈希值:md5(uniqid(microtime(true),true));
以及$destination移到函數(shù)體內(nèi)就好了
2019-05-05
你不貼錯(cuò)誤截圖,如何排查