本篇文章给大家带来的内容是关于教你使用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><link><script></script><!-- the main fileinput plugin file --><script></script><!-- optionally if you need translation for your language then include locale file as mentioned below --><script></script>
最简单的初始化代码如下:
<input> $("#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>'); input.attr('value', response.key); $('form').append(input); });以上就是本篇文章的全部内容了,更多bootstrap的内容,大家可以关注php中文网的bootstrap教程。