将图片转成二进制储存在数据库中

2018-09-26

<!DOCTYPE html>
<html>
    <head>
        <meta charset="{CHARSET}">
        <title></title>
    </head>
    <body>
        <input type="file" name="" id="inputs" value="" />
        <div id="dd"></div>
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script type="text/javascript">    
        $('#inputs').change(function(){
            var fil = this.files;
            console.log(fil.length)
            for(var i=0;i<fil.length;i++){
                console.log(fil[i])
                console.log(11111111111111111111111111111111111)
                reads(fil[i])
            }
        })            
        function reads(fil){
            var reader = new FileReader;
            reader.readAsDataURL(fil);
            reader.onload = function(){
                $('#inputs').after("<img src='"+reader.result+"'>");
                console.log(reader.result)
            }
        }            
        </script>        
    </body>
</html>

 

posted @ 2018-09-26 15:41  渺茫  阅读(524)  评论(0编辑  收藏  举报