参考原 upload.html 文件
<link rel="stylesheet" href="{pboot:sitetplpath}/bootstrap/css/bootstrap.min.css" >
<script src="{pboot:sitetplpath}/bootstrap/js/bootstrap.min.js"></script>
<link href="{pboot:sitetplpath}/fileinput/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<link href="{pboot:sitetplpath}/fileinput/themes/explorer-fa/theme.css" media="all" rel="stylesheet" type="text/css"/>
<script src="{pboot:sitetplpath}/fileinput/js/plugins/sortable.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/js/locales/fr.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/js/locales/es.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/themes/explorer-fa/theme.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/themes/fa/theme.js" type="text/javascript"></script>
<script src="{pboot:sitetplpath}/fileinput/js/locales/zh.js" type="text/javascript"></script>
上传:<span id="fileName"></span><input class="btn btn-success file" type="button" value="上传文件">
<div class="modal fade" id="fileBox" tabindex="-1" role="dialog" aria-labelledby="fileBoxLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="fileBoxLabel">文件上传</h4>
</div>
<div class="modal-body">
<div class="file-loading">
<input id="fileInput" name="upload" type="file" data-msg-placeholder="请选择要上传的文件">
</div>
<div id="kartik-file-errors"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary uploadSubmit">上传</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
$(document).on('ready', function() {
var target;
$(".file").on("click", function() {
target = $(this).data("target");
upload('fileInput', false, false, true, 1);
$("#fileBox").modal("show");
});
function upload(inputName, showPreview, dropZoneEnabled, autoReplace, maxFileCount) {
$("#" + inputName).fileinput({
language: 'zh',
showUpload: false,
showPreview: showPreview,
dropZoneEnabled: dropZoneEnabled,
autoReplace: autoReplace,
elErrorContainer: '#kartik-file-errors',
uploadAsync: false,
maxFileCount: maxFileCount,
uploadUrl: '{pboot:upload}' //文件上传接口
}).on("filebatchuploadsuccess", function(event, data, previewId, index) {
if (data.response.code) {
$('#fileName').html(data.response.data.src)
$("#" + inputName).fileinput('reset');
$("#uploadBox").modal("hide");
$("#fileBox").modal("hide");
$("#uploadBoxs").modal("hide");
} else {
alert(data.response.data);
}
});
$(".uploadSubmit").on("click", function() {
$("#" + inputName).fileinput("upload");
});
}
});
全局查找 “请先登录”