简单上传自己写个js算了,用插件影响服务器性能
<script>
$(function () {
$("#upload").click(function () {
$("#select_file").click()
});
$("#select_file").change(function () {
let file_obj = document.getElementById('select_file').files[0];
let form = new FormData();
form.append('file',file_obj);
$.ajax({
url: '/admin/upload/image',
data: form,
method: 'POST',
cache: false, //不设置缓存
processData: false, // 不处理数据
contentType: false, // 不设置内容类型
error: function(xhr){
alert(xhr.responseJSON.errors.file[0])
},
success: function (res) {
if(res.status===1){
$("#img_show").attr("src",res.msg);
$("#image_url").val(res.msg);
}
}
})
})
})
</script>
<div class="form-group" id="upload_icon">
<label class="control-label col-lg-2">分类图标</label>
<div class="col-lg-10">
<form method="post" id="upload_img" enctype="multipart/form-data">
@csrf
<input type="file" name="image" class="btn btn-default" style="display: none"
id="select_file">
<button type="button" class="btn btn-info" id="upload">上传图片</button>
</form>
<br>
<br>
<img src="/vendor/admin/assets/images/upload.jpg" width="50px;" height="50px;"
class="img-preview" id="img_show">
</div>
<div style="display:none;">
<input type="file" name="image" class="image_upload">
<input type="hidden" name="image" id="image_url">
</div>
</div>