First, the front-end parts need to set up a good control, here using the HTML5 in the new properties of input multiple can be good to solve the previous upload multiple need to click multiple " Upload Button "Trouble:
1 <formAction=""Method= "POST"enctype= "Multipart/form-data">2 3 <inputtype= "File" id= "Upload_imgs"name= "upload_imgs[]"multiple= "multiple">4 5 <inputtype= "Submit"value= "Submit Upload">6 </form>
If you need to select a file, you can use the files.length property for the number of files selected by the user before submission, such as:
Document.upload_imgs.files.length to get the number of selected files in the above form.
Next is the processing in PHP :
1 if(!Empty($_files)){2 //print_r ($_files[' Upload_imgs '); exit;3 4 functionUpload_files ($name){5 $files=$_files[$name];6 7 $k 1=$k 2=Array();8 foreach($files as $key=$val){9 if($key= = ' Tmp_name '){Ten $k 1=$val; One } A if($key= = ' name '){ - $k 2=$val; - } the } - - //$filenames Save the moved file name - $filenames=Array(); + foreach($k 1 as $key=$val){ - //$rename Get the original file name (not including the suffix name) + $rename=substr($k 2[$key],0,Strpos($k 2[$key],‘.‘)); A at //$suffix file suffix name - $suffix=substr($k 2[$key],Strpos($k 2[$key],‘.‘)); - - //Echo MD5 ($rename). $suffix; exit; - $time= Time(); - Copy($val, './upload/'.MD5($rename.$time) .$suffix); in - $filenames[] = ' upload/'.MD5($rename.$time) .$suffix; to } + Print_r($filenames);Exit; - //returns the uploaded file path as an array the return $filenames; * } $ Panax Notoginseng -Upload_files (' Upload_imgs '); the + A}
The PHP file executes the upload_files () function to get the file path after the upload.
So the batch upload is done.
Welcome to the various methods reproduced, but please be sure to indicate the source.
PHP Batch upload Once click to select multiple