<form id="ajaxform" enctype="multipart/form-data" class="form">
<input type="file" class="input-file" accept="image/gif, image/jpeg" id="uploadimg" name="image[]" multiple /> <input type="button" id="postbtn" class="input-btn" value="上传" />
</form> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
<!--
$(function(){ $("#postbtn").on("click",function(){
var formData = new FormData($("#ajaxform")[0]);
console.log(formData);
$.ajax({
type: "POST",
data:formData,
url:"imgupload",
contentType:false,
processData:false,
success: function(data){
console.log(data);
}});
});
});
//-->
</script>
//图片上传 ROOT_PATH.'uploads'
public function imgupload(){ $files = request()->file('image');
foreach($files as $file){
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->validate(['size'=>156780,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'upload');
if(!$info){
// 上传失败获取错误信息
echo $file->getError();
}
}
}