Js base64位圖片上傳

圖片瀏覽,將瀏覽過的單個圖片通過base64爲方法放到本地,不進行二進制流,減輕服務器壓力

<a href="javascript:void(0)" name="photo">本地圖片瀏覽</a>&nbsp;&nbsp;
              <div style="display: none;">
                 <input type="file" name="seek_photo" id="file_seek" >
              </div>
 <!-- 圖片臨時存放div -->

                <div id="pic_shou" style="width: 250px;height: 400px; background: orange;  position: absolute;
  left: 10px;top: 660px; display: block;">已經瀏覽的圖片<br></div>
               <!-- 圖片臨時存放div -->

              <!-- js圖片瀏覽=====base64位本地顯示 -->
               <script type="text/javascript">
                $('a[name="photo"]').click(function(){
                  // alert('點擊確定瀏覽本地圖片');
                   $('input[name="seek_photo"]').click();

                });
                // 圖片改變事件
                $('input[name="seek_photo"]').change(function(){

                  var file_seek = document.getElementById('file_seek').files[0];
                  // base64上傳本地
                  var reader = new FileReader();

                  reader.onloadend = function(){

                  console.log(reader);

                //發送給服務器
              //ws.send('{"type":"send_pic","content":"'+reader.result+'","desc":""}'); //Workerman數據推送

                var _img = '<img src="'+reader.result+'" width="110" />&nbsp;';

                $('#pic_shou').append(_img);

                };

                if(file_seek){
                    reader.readAsDataURL(file_seek);
                  }else{
                    preview.src = "";
                };


                });

               </script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章