首页 技术 正文
技术 2022年11月6日
0 收藏 942 点赞 510 浏览 2110 个字

引入相关js

<script src="{{ asset('bootstrap-fileinput/js/fileinput.js') }}"></script>
<script src="{{ asset('bootstrap-fileinput/js/fileinput.min.js') }}"></script>

html代码

<div class="form-group {{ $errors->has('idcard_front') ? ' has-error' : '' }}">
<label class="control-label col-sm-2" for="inputSuccess3">身份证正面</label>
<div class="col-sm-6">
<input id="input-b4b" name="idcard_front" type="file" value="">
<input id="idcard_front" name="id_card_front" type="hidden" value="">
</div>
@if ($errors->has('idcard_front'))
<span class="help-block">
<strong>{{ $errors->first('idcard_front','请上传您的身份证正面') }}</strong>
</span>
@endif
</div>

js代码

$("#input-b4b").fileinput({
language: 'zh', //设置语言
uploadUrl: "url", //上传的地址
allowedFileExtensions: ['jpg', 'jpeg', 'gif', 'png'],//接收的文件后缀
browseLabel: '选择文件',
removeLabel: '删除文件',
removeTitle: '删除选中文件',
cancelLabel: '取消',
cancelTitle: '取消上传',
uploadLabel: '上传',
uploadTitle: '上传选中文件',
dropZoneTitle: "请通过拖拽图片文件放到这里",
dropZoneClickTitle: "或者点击此区域添加图片",
uploadAsync: true, //默认异步上传
showUpload: true, //是否显示上传按钮
showRemove: true, //显示移除按钮
showPreview: true, //是否显示预览
showCaption: false,//是否显示标题
browseClass: "btn btn-primary", //按钮样式
dropZoneEnabled: true,//是否显示拖拽区域
//minImageWidth: 50, //图片的最小宽度
//minImageHeight: 50,//图片的最小高度
//maxImageWidth: 1000,//图片的最大宽度
//maxImageHeight: 1000,//图片的最大高度
maxFileSize: 2000,//单位为kb,如果为0表示不限制文件大小
//minFileCount: 0,
maxFileCount: 10, //表示允许同时上传的最大文件个数
enctype: 'multipart/form-data',
validateInitialCount: true,
previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!"
}).on("filebatchselected", function (event, files) {
$(this).fileinput("upload");
})
.on("fileuploaded", function (event, data) {
if (data.response) {
var picdir = data.response;
$("#idcard_front").val(picdir);
}
});
 

说明一下:引入汉化包没有生效,mmp!!! 自己汉化吧!

后台处理代码:

public function uploadimg(Request $request)
{
if($request->isMethod('post'))
{ $file = $request->file('idcard_front');
if($file){
$extension = $file -> guessExtension();
$newName = str_random(18).".".$extension;
$file -> move(base_path().'/public/storage/uploads',$newName);
$idCardFrontImg = '/upload/file/'.$newName;
return json_encode($idCardFrontImg);
}else{
$idCardFrontImg = '';
return json_encode($idCardFrontImg);
}
}
}

暂时做个备份,仅供参考!多多交流!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905