This article is mainly to share a PHP implementation of a multi-file upload method, before the implementation of the form file type input select multiple images of the time to find a way may not be the best but the pro-test is feasible and support IE7 above and Chrome browser, hope to help everyone.
Select the Multiple property with normal multiple files in the form
<input type= "file" id= "image" class= "file image hidden" name= "image[]" multiple= "true" >
Then use Ajaxfileupload or other means to submit
Convert named file files $file[‘image']
to JSON print
Normal format
{"Name": "7332.png", "type": "Image\/png", "Tmp_name": "\/TMP\/PHPLQPPVR", "error": 0, "Size": 659}
But at this point the result is
{"Name": ["7656.png", "7718.png"], "type": ["Image/png", "Image/png"], "tmp_name": ["/TMP/PHPDZSOVJ", "/TMP/PHPP8KWMT" ], "error": [0,0], "size": [357,662]}
All of the properties are sorted into arrays in order
You can use the following code to save the picture
if (!isset ($_files[$field])) {return new Jsonresponse (' ErrorCode ' =>1, ' message ' = ' please upload file ')} Rename $_file store multiple files upload $arrayfile = Array (); foreach ($_files[$field] as $key + $value) {$i = 0; if (Is_array ($value)) {foreach ($value as $v) {$i + +; After renaming, re-placing the Super global variable _file ensure that the key name is unique and can be uploaded directly $name = $field. ' _split_ '. $i; $_files[$name] [$key] = $v; }}}//whether to upload multiple files if ($i > 0) {for ($j = 1; $j <= $i; $j + +) {Array_push ($arrayFile, $field. ' _split_ '. $J); }}else{Array_push ($arrayFile, $field);}//Traverse file Multiple Files upload foreach ($arrayFile as $file) {if (Isset ($_files[$file]) &&A mp $_files[$file [' name ']) {//Custom upload method specific content slightly $data = $this->uploadfile ($file, $path, Uniqid ()); if (Isset ($data) &&!empty ($data)) {if (!isset ($data [' errors ')]) {//upload results stored in $result multiple picture addresses using comma concatenation if (Isset ($result)) {$result = array (' ErrorCode ' =>0, ' message ' = = $result [' message ']. ',' . Reset ($data)); }else{$result = array(' ErrorCode ' =>0, ' message ' =>reset ($data)); }}else{//The following is the return error message if (Is_array (Reset ($data))) {$message = reset ($data) [0]; }else{$message = reset ($data); } $result = Array (' errorCode ' = = 1, ' message ' = = $message); }} else {$result = array (' ErrorCode ' =>1, ' message ' = ' upload failed '); Break }} else {$result = array (' ErrorCode ' =>1, ' message ' = ' please upload file '); Break }}//return the upload result return $result;