is to add a function based on the previous single file upload:
1<?PHP2 /**3 * Upload function4 * @param $tmp Five informations of _file $_files, such as Upload ($_files (' Mingzi ')5 * $_files inside name is your corresponding HTML code in the upload file of that name6 * @return BOOL failed to return false, success is true7 */8$tmp _file=$_files[' Picture'];9 function upload ($tmp _file) {Ten One /** A * Is there an error - */ - the if($tmp _file['Error']!=0){ -Echo'File Upload error'; - return false; - } + /** - * Size, + * This function is set by itself, but it should be initialized, that is, the value is variable, not a fixed value. A */ at -$max _size=1024x768*1024x768;//The maximum size you set - if($tmp _file['size']>$max _size) { -Echo"file too large"; - return false; - } in /** - * Verify the suffix name, to * with authentication suffix and mime method + */ - //the first is to verify the suffix name the$tmp _FILE_ZHUI=STRRCHR ($tmp _file['name'],'.') ; * //the STRRCHR function is to cut the last occurrence of a string. Include this. All subsequent interception $ //a map array of suffixes, which is actually the suffix table that satisfies the condition (represented by an associative array)Panax Notoginseng$tmp _file_zhui_list=Array ( - '. PNG','. gif','. JPEG','. jpg' the ); + if(!In_array ($tmp _file_zhui, $tmp _file_zhui_list)) { AEcho"There is a problem with the file format"; the return false; + } - //That's the $_files[' type '. There is a format, the following is the corresponding mapping table $$tmp _file_zhui_mimelist=Array ( $ '. PNG'=>array ('Image/png','Image/x-png'), - '. jpg'=>array ('Image/jpeg','Image/x-pjpeg'), - '. JPEG'=>array ('Image/jpeg','Image/pjpeg'), the '. gif'=>array ('Image/gif'), - );Wuyi$old _list=array ();//The following directly with $old_list not, I think this is a statement, this is the addition of the //To get the real mapping table, because in my suffix mapping table, may not be these four, once changed, my following mapping relationship, I have to change myself, so, I use a foreach, what is the suffix above, I will give him what $_file[' type ' format, And get the MIME mapping table I want. - foreach($tmp _file_zhui_list as$value) { Wu foreach($tmp _file_zhui_mimelist[$value] as$key =$item) { - //var_dump ($tmp _file_zhui_mimelist[$value [$key]); About$new _mime_list=Array_merge ($old _list, (array) $tmp _file_zhui_mimelist[$value] [$key]); $$old _list=$new _mime_list; - } - - } A //Go heavy +$new _mime_list=Array_unique ($new _mime_list); the - //then verify with MIME $$phpfinfo =NewFinfo (fileinfo_mime_type); the$f _type= $phpfinfo->file ($tmp _file['Tmp_name']); the echo $f _type; the if(!In_array ($f _type, $new _mime_list)) { theEcho"file format is incorrect"; - return false; in } the //suffix verification is complete. the //Create a folder to save my temporary files About if(!is_dir ('./wangchao')){ themkdir'./wangchao'); the } the +$sub _dir_name=date ('y--m-d-h');//interception Date Hour - //Unipid is to produce a random name, you can experiment with echo uniqid (); theMove_uploaded_file ($tmp _file['Tmp_name'],'./wangchao/'. Uniqid ('Wang_'. $sub _dir_name.'_'). $tmp _file_zhui);Bayi return true; the } the upload ($tmp _file); - - the /* the The basic steps are: the ① See if $_files[' error ' has burst the ② Look at the size of the file - ③ Look at the format of the file, divided into suffixes and mime authentication the ④ Create a folder to access temporary upload files the ⑤ return Results the 94 */ the function Uploadsome ($tmp _files) { the foreach($tmp _files as$key =$value) { the$tmp _file['name']= $tmp _files['name'[$key];98$tmp _file['type']= $tmp _files['type'[$key]; About$tmp _file['Tmp_name']= $tmp _files['Tmp_name'[$key]; -$tmp _file['Error']= $tmp _files['Error'[$key];101$tmp _file['size']= $tmp _files['size'[$key];102 upload ($tmp _file);103 }104}
Multi-File upload looks like:
101) PHP, multi-File upload