PHP multi-input file upload
Foreground html jquery code background PHP processing foreground html
** Note that you must use the name [] method and the same name.
** For a form with a file, you must add "enctype =" multipart/form-data "to form"
Jquery submits form
$ (# Form). form ('submit ', {url: url, success: function (data) {// process returned data }});
PHP background processing
// Receive and process FILES $ fileArray = $ _ FILES ['imagesupload']; // obtain the file $ upload_dir = public_path () based on the Request name (). /upload/carPic/; $ userID = Session: get ('userid'); $ nowTime = date (YmdHis, time (); $ I = 0; $ successName = array (); foreach ($ fileArray ['error'] as $ key => $ error) {// traverse the processing file if ($ error = UPLOAD_ERR_ OK) {$ temp_name = $ fileArray ['tmp _ name'] [$ key]; $ file_name = $ userID. '-'. $ nowTime. $ I. $ fileArray ['name'] [$ key]; mov E_uploaded_file ($ temp_name, $ upload_dir. $ file_name); array_push ($ successName, $ file_name); // Add the name of the uploaded file to the array} else {return '{flag: 0, flagmsg: Upload [File '. $ key. '] failed !!} ';}$ I ++ ;}$ flag = array ('flag' => 1, 'flagmsg' => 'File Uploaded successfully! '); $ Names = array ('names' => $ successName); return json_encode (array_merge ($ flag, $ names); // return the upload result, and return the names of all uploaded files.
PHP code is very simple and I will not explain it one by one. Thank you for your guidance!