图片上传存储数据库
<div class="layui-input-block"> <input type="file" accept="*/*" name="file" id="FileImg" onchange="xmTanUploadImg(this)"> <img src="" id="avarimgs" width="50px" height="50px"> </div>
<script> function xmTanUploadImg(obj) { var file = obj.files[0]; console.log("fileName:" + file.name)//文件名 console.log("file.size = " + file.size);//文件大小 var reader = new FileReader(); reader.onload = function (e) { console.log(e)// 对象里面的target.result就是base64编码 var img = document.getElementById("avarimgs"); img.src = e.target.result; // $("#typeIcon").val(e.target.result) } reader.readAsDataURL(file) } </script>
该方法只针对于直接储存base64