- 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