PHP multi-inputfile file upload. PHP multi-inputfile file Upload foreground htmljquery code background PHP processing foreground html ** note that name writing should use name [] method, and use the same name **. Note that multiple input file files with file are uploaded in PHP.
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!
Http://www.bkjia.com/PHPjc/970256.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/970256.htmlTechArticlePHP multi input file upload front-end html jquery code back-end PHP front-end html ** note name writing, must use name [] method, and use the same name ** to pay attention to the form with file...