前台html
<form id="form" method="post" enctype="multipart/form-data">
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<a class="easyui-linkbutton" icon="icon-add" id="uploadImage_input">图片上传</a>
</form>
** 注意name的写法,都要使用name[]方式,而且用同一个name
** 注意带有file的表单,form一定要加:enctype=”multipart/form-data”
jquery 提交form表单
$("#form").form('submit',{
url:url,
success:function(data){
}
});
PHP 后台处理
$fileArray = $_FILES['imagesUpload'];
$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.']失败!<br/>!"}';
}
$i++;
}
$flag = array('flag'=>1,'flagmsg'=>'文件上传成功!');
$names = array('names'=>$successName);
return json_encode(
array_merge($flag,$names)
);
PHP代码都非常easy,就不一一解释了。欢迎指导。
尊重原创。转载请注明出处:http://blog.csdn.net/a437629292/article/details/44337295
请发表评论