6-12 2,067 views
<div>
<div class="col-md-3">
<div class="form-group">
<label>你的头像</label>
<div id="dropzone" style="height: 220px;" class="dropzone"></div>
</div>
</div>
</div>
</div>
Dropzone.autoDiscover = false
var myDropzone = new Dropzone("div#dropzone", {
url: "/image/upload",
// uploadMultiple: false,
paramName: 'images',
addRemoveLinks: true,
maxFiles: 1,
maxFilesize: 2, // 文件大小,单位:MB
acceptedFiles: '.jpg,.jpeg,.png',
clickable: true,
dictRemoveFile: '删除',
params: {"_token": token},
dictMaxFilesExceeded: '只能上传一张头像图片',
dictInvalidFileType: "文件类型只能是*.jpg,*.png,*.jpeg",
dictDefaultMessage: '点击这里上传图片',
dictFileTooBig: '文件太大,超出最大(2M)限制',
init: function () {
//只上传一个
this.on("maxfilesexceeded", function(file) {
this.removeAllFiles();
this.addFile(file);
});
},
});
参考:https://stackoverflow.com/questions/35838073/how-to-stop-upload-a-second-image-on-dropzone