Home > php教程 > php手册 > 多图上传压缩base64存入数据库

多图上传压缩base64存入数据库

WBOY
Release: 2016-06-07 11:35:24
Original
1597 people have browsed it

不BB直接上代码
html部分<div> <br>     <div> <br> <br>         <form> <br>             <input><br>             <div> <br>             </div> <br>             <input><br>         </form> <br> <br>     </div> <br> </div> <br> <script></script><br> <script></script><br> <script></script><br> <script></script>user.js部分$(function(){<br>     $('#up').change(function(){<br>         var obj=document.getElementById('up');<br>         lrz(obj.files[0], {<br>             width: 640,<br>             height: 640,<br>             // 压缩开始<br>             before: function () {<br>                 console.log('压缩开始');<br>             },<br>             // 压缩失败<br>             fail: function (err) {<br>                 console.error(err);<br>             },<br>             // 压缩结束(不论成功失败)<br>             always: function () {<br>                 console.log('压缩结束');<br>             },<br>             // 压缩成功<br>             done: function (results) {<br>                 var id=Date.parse(new Date());<br>                 var html= $('#code').html();<br>                 console.log('压缩成功');<br>                 $('#code').html(html+'<div> <span>x</span><img alt="多图上传压缩base64存入数据库" ><input> </div>');<br>                 $('#'+id).attr('src', results.base64);<br>                 $('#v'+id).val(results.base64);<br>             }<br>         })<br>     });<br> })<br> function rem(id){<br>     $('#'+id).parent().remove();<br> }uploadPreview1.1.js部分,当然这是一个插件,网上有下载的/*<br> *名称:图片上传本地预览插件 v1.1<br> *作者:周祥<br> *时间:2013年11月26日<br> *介绍:基于JQUERY扩展,图片上传预览插件 目前兼容浏览器(IE 谷歌 火狐) 不支持safari<br> *插件网站:http://keleyi.com/keleyi/phtml/image/16.htm<br> *参数说明: Img:图片ID;Width:预览宽度;Height:预览高度;ImgType:支持文件类型;Callback:选择文件显示图片后回调方法;<br> *使用方法: <br> <div> <br> <img alt="多图上传压缩base64存入数据库" > </div> <br> <input><br> 把需要进行预览的IMG标签外 套一个DIV 然后给上传控件ID给予uploadPreview事件<br> $("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120, ImgType: ["gif", "jpeg", "jpg", "bmp", "png"], Callback: function () { }});<br> */<br> jQuery.fn.extend({<br>     uploadPreview: function (opts) {<br>         var _self = this,<br>             _this = $(this);<br>         opts = jQuery.extend({<br>             Img: "ImgPr",<br>             Width: 100,<br>             Height: 100,<br>             ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],<br>             Callback: function () {}<br>         }, opts || {});<br>         _self.getObjectURL = function (file) {<br>             var url = null;<br>             if (window.createObjectURL != undefined) {<br>                 url = window.createObjectURL(file)<br>             } else if (window.URL != undefined) {<br>                 url = window.URL.createObjectURL(file)<br>             } else if (window.webkitURL != undefined) {<br>                 url = window.webkitURL.createObjectURL(file)<br>             }<br>             return url<br>         };<br>         _this.change(function () {<br>             if (this.value) {<br>                 if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {<br>                     alert("选择文件错误,图片类型必须是" + opts.ImgType.join(",") + "中的一种");<br>                     this.value = "";<br>                     return false<br>                 }<br>                 if ($.browser.msie) {<br>                     try {<br>                         $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))<br>                     } catch (e) {<br>                         var src = "";<br>                         var obj = $("#" + opts.Img);<br>                         var div = obj.parent("div")[0];<br>                         _self.select();<br>                         if (top != self) {<br>                             window.parent.document.body.focus()<br>                         } else {<br>                             _self.blur()<br>                         }<br>                         src = document.selection.createRange().text;<br>                         document.selection.empty();<br>                         obj.hide();<br>                         obj.parent("div").css({<br>                             'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',<br>                             'width': opts.Width + 'px',<br>                             'height': opts.Height + 'px'<br>                         });<br>                         div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src<br>                     }<br>                 } else {<br>                     $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))<br>                 }<br>                 opts.Callback()<br>             }<br>         })<br>     }<br> });lrz.mobile.min.js需要网上下载
演示地址:http://1.jspgame.applinzi.com/Home/Game/user

AD:真正免费,域名+虚机+企业邮箱=0元

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template