thinkphp 5.1 同时选中多个文件上传

 <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();
}
}
}
上一篇:原创:MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 4、创建数据上下文和数据实体模型


下一篇:ABP Framework:移除 EF Core Migrations 项目,统一数据上下文