PHP multi-inputfile file Upload _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.