您好,欢迎访问一九零五行业门户网

教你使用bootstrap file input上传图片文件

本篇文章给大家带来的内容是关于教你使用bootstrap file input上传图片文件,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
项目中经常会遇到文件上传,管理多文件上传过程的需求。
bootstrap file input组件算是不错的解决方案
项目github地址:https://github.com/kartik-v/b...
组件开发多年,功能强大,最简单的集成方式却并不复杂,首先下载源代码:
php composer.phar require kartik-v/bootstrap-fileinput @dev
插件兼容bootstrap3/4
引入相关文件:
<!-- bootstrap 4.x is supported. you can also use the bootstrap css 3.3.x versions --><link rel="stylesheet" href="/css/bootstrap.min.css"><link href="/bootstrap-fileinput/4.4.9/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /><script src="/jquery-3.2.1.min.js"></script><!-- the main fileinput plugin file --><script src="/bootstrap-fileinput/4.4.9/js/fileinput.min.js"></script><!-- optionally if you need translation for your language then include locale file as mentioned below --><script src="/bootstrap-fileinput/4.4.9/js/locales/(lang).js"></script>
最简单的初始化代码如下:
<input type="file" id="input-id" />$(#input-id).fileinput();
但要完成一个基本可用的状态,还需要增加以下配置项:
$(#cover).fileinput({    language: zh,    showcaption: false, // 不显示本地文件名    allowedfiletypes: ['image'], // 只允许上传图片    allowedfileextensions: [jpg, jpeg, png, gif],     uploadurl: {{ url('uploads/image') }} //上传图片的服务器地址}).on('fileuploaded', function(event, data, previewid, index){    var response = data.response;    $('input#coveruploader').attr('required', false);    var input = $('<input type="hidden" name="cover" />');    input.attr('value', response.key);    $('form').append(input);});
以上就是本篇文章的全部内容了,更多bootstrap的内容,大家可以关注的bootstrap教程。
以上就是教你使用bootstrap file input上传图片文件的详细内容。
其它类似信息

推荐信息