PHP multiple Input File upload

Source: Internet
Author: User

    • Foreground HTML
    • jquery Code
    • Background PHP processing
Foreground HTML
<form id="Form" Method="POST"Enctype="Multipart/form-data"><inputclass="Imagesupload"  Type="File"Name="imagesupload[]"style="WIDTH:152PX;"/><inputclass="Imagesupload"  Type="File"Name="imagesupload[]"style="WIDTH:152PX;"/><inputclass="Imagesupload"  Type="File"Name="imagesupload[]"style="WIDTH:152PX;"/><inputclass="Imagesupload"  Type="File"Name="imagesupload[]"style="WIDTH:152PX;"/><aclass="Easyui-linkbutton"icon="Icon-add"Id="Uploadimage_input"> Image Upload </a></form>

* * Note the wording of name, use name[], and use the same name
* * Note the form with file, the form must be added: Enctype= "Multipart/form-data"

jquery submits Form form
$("#form").form(‘submit‘,{  url:url,  success:function(data){    //处理返回数据  }});
PHP Background processing
//Receive processing files$fileArray=$_files[' Imagesupload '];//Get the file according to the name of the request$upload _dir= Public_path ()."/upload/carpic/";$userID= Session::get (' UserID ');$nowTime= Date ("Ymdhis", time ());$i=0;$successName=Array();foreach($fileArray[' ERROR '] as $key=$error){//Traverse processing files  if($error= = UPLOAD_ERR_OK) {$temp _name=$fileArray[' 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 file name of the upload successfully to the array}Else{return ' {' flag ': 0, ' flagmsg ': ' Upload [file ' ].$key.'] Failed!<br/>! "} '; }$i++;}$flag=Array(' flag '=1,' flagmsg '=' File upload succeeded! ');$names=Array(' names '=$successName);returnJson_encode (Array_merge ($flag,$names));//Returns the upload result and returns the name of all files after successful upload

PHP code is very simple, not a single explanation. Welcome to guide!
Respect the original, reproduced please specify the source: http://blog.csdn.net/a437629292/article/details/44337295

PHP multiple Input File upload

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.