** Pay attention to how to write name, use name[] method, and use the same name
** Pay attention to the form with file. The form must add: enctype="multipart/form-data"
<code class="hljs" javascript="">$(#form).form('submit',{ url:url, success:function(data){ //处理返回数据 } });</code>
<code class="hljs" php="">//接收处理文件 $fileArray = $_FILES['imagesUpload'];//根据请求的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){ //遍历处理文件 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);//把上传成功的文件名称加入数组 }else{ return '{flag:0,flagmsg:上传[文件'.$key.']失败! !}'; } $i++; } $flag = array('flag'=>1,'flagmsg'=>'文件上传成功!'); $names = array('names'=>$successName); return json_encode( array_merge($flag,$names) );//返回上传结果,并返回上传成功后的所有文件的名称</code>
The PHP codes are very simple, so I won’t explain them one by one. Welcome to guide!