PHP multiple input File file upload

Source: Internet
Author: User
Tags add array file upload key php code return
Foreground HTML jquery code background PHP processing

Foreground HTML

  
    图片上传  

* * Note that the name is written by using the name[] method and using the same name
* * Note the form with file, form must add: enctype= "Multipart/form-data"

jquery Submit Form Form

$(#form).form('submit',{
  url:url,
  success:function(data){
    //处理返回数据
  }
});

php background processing

 //receive processing file $fileArray = $_files[' Imagesupload '];//gets the file according to the requested name $upload _dir = Public_path ().
/upload/carpic/;
$userID = Session::get (' UserID ');
$nowTime = Date (Ymdhis, Time ());
$i = 0;
$successName = Array (); foreach ($fileArray [' Error '] as $key => $error) {//Traversal process file if ($error = = UPLOAD_ERR_OK) {$temp _name = $FILEARR
    ay[' Tmp_name ' [$key];
    $file _name = $userID. $nowTime $i. $fileArray [' name '] [$key];
    Move_uploaded_file ($temp _name, $upload _dir. $file _name); Array_push ($successName, $file _name)//Add the uploaded file name to the array}else{return ' {flag:0,flagmsg: Upload [file '. $key. ']
  Failure!!} ';
} $i + +;
$flag = Array (' flag ' =>1, ' flagmsg ' => ' file uploaded successfully! ');
$names = Array (' names ' => $successName); Return Json_encode ($flag, $names))//returns the upload result and returns the name of all files after the successful upload  

PHP code is very simple, not explained. Welcome to guide!
 



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.