Home > Web Front-end > JS Tutorial > Detailed explanation of examples of Bootstrap fileinput file upload component

Detailed explanation of examples of Bootstrap fileinput file upload component

PHPz
Release: 2018-10-16 15:46:28
Original
7653 people have browsed it

This article mainly introduces the use of the Bootstrap fileinput file upload component in detail. It has a certain reference value. Interested friends can refer to it [Related video recommendation: Bootstrap Tutorial

1. Usage method

1. Import dependent js and css files:

<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/fileinput.min.css" />
<script type="text/javascript" src="js/jquery-3.2.1.js" ></script>
<script type="text/javascript" src="js/bootstrap.js" ></script>
<script type="text/javascript" src="js/fileinput.js" ></script>
<script type="text/javascript" src="js/zh.js" ></script>
<script type="text/javascript" src="js/my.js" ></script>
Copy after login

2. Create a file input area

<form>
 <p class="form-group">
  <h3>Bootstrap File Input Demo1</h3>
 </p>

 <input name="uploadFile" type="file" id="uploadFile" multiple class="file-loading" />
</form>
Copy after login

3. Write the my.js file and initialize the file upload component

$(function() {
 //初始化fileinput
 var fileInput = new FileInput();
 fileInput.Init("uploadFile", "http://127.0.0.1/testDemo/fileupload/upload.action");
});

//初始化fileinput
var FileInput = function() {
 var oFile = new Object();

 //初始化fileinput控件(第一次初始化)
 oFile.Init = function(ctrlName, uploadUrl) {
  var control = $(&#39;#&#39; + ctrlName);

  //初始化上传控件的样式
  control.fileinput({
   language: &#39;zh&#39;, //设置语言
   uploadUrl: &#39;http://127.0.0.1/testDemo/fileupload/upload.action&#39;, //上传的地址
   allowedFileExtensions: [&#39;jpg&#39;, &#39;png&#39;, &#39;gif&#39;], //接收的文件后缀
   uploadAsync: true, //默认异步上传

   showUpload: false, //是否显示上传按钮
   showRemove: true, //显示移除按钮
   showCaption: true, //是否显示标题

   dropZoneEnabled: true, //是否显示拖拽区域

   //minImageWidth: 50, //图片的最小宽度
   //minImageHeight: 50,//图片的最小高度
   //maxImageWidth: 1000,//图片的最大宽度
   //maxImageHeight: 1000,//图片的最大高度
   //maxFileSize:0,//单位为kb,如果为0表示不限制文件大小
   //minFileCount: 0,
   maxFileCount: 10, //表示允许同时上传的最大文件个数
   enctype: &#39;multipart/form-data&#39;,

   browseClass: "btn btn-primary", //按钮样式: btn-default、btn-primary、btn-danger、btn-info、btn-warning  
   previewFileIcon: "<i class=&#39;glyphicon glyphicon-king&#39;></i>",

  });

  //文件上传完成之后发生的事件
  $("#uploadFile").on("fileuploaded", function(event, data, previewId, index) {

  });
 }
 return oFile; //这里必须返回oFile对象,否则FileInput组件初始化不成功
};
Copy after login

2. Rendering

1. Initialization interface:

2. Multiple files can be realized Upload:

3. Click a file to preview in full screen:

3. Options Introduction

IV. Introduction to Method

I will write it down when I have time

5. Source code download

Bootstrap fileinput file upload component

The above is the detailed content of Detailed explanation of examples of Bootstrap fileinput file upload component. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template