久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何實(shí)現(xiàn)圖片轉(zhuǎn)base64格式并上傳

      php實(shí)現(xiàn)圖片轉(zhuǎn)base64格式并上傳的方法:1、將圖片轉(zhuǎn)化為base64格式;2、通過ajax將圖片上傳到服務(wù)器端;3、在服務(wù)器端重新轉(zhuǎn)化圖片格式并進(jìn)行儲存即可。

      php如何實(shí)現(xiàn)圖片轉(zhuǎn)base64格式并上傳

      本文操作環(huán)境:windows10系統(tǒng)、php 7、thinkpad t480電腦。

      在實(shí)際開發(fā)項(xiàng)目的過程中處理圖片上傳是一定會遇到的,例如使用thinkphp的小伙伴一定很熟悉import("@.ORG.UploadFile");的上傳方式吧。今天我們就來講一講使用html base 64上傳圖片的方法,一起來看看吧。

      主要是用到html5 FileReader的接口,既然是html5的,所支持的瀏覽器我就不多說啦。

      可以大概的講一下思路,其實(shí)也挺簡單。選擇了圖片之后,js會先把已選的圖片轉(zhuǎn)化為base64格式,然后通過ajax上傳到服務(wù)器端,服務(wù)器端再轉(zhuǎn)化為圖片,進(jìn)行儲存的一個(gè)過程。

      咱們先看看前端的代碼。

      html部分

      <input type="file" id="imagesfile">

      js部分

      $("#imagesfile").change(function (){               var file = this.files[0];        //用size屬性判斷文件大小不能超過5M ,前端直接判斷的好處,免去服務(wù)器的壓力。    if( file.size > 5*1024*1024 ){          alert( "你上傳的文件太大了!" )     }        //好東西來了    var reader=new FileReader();     reader.onload = function(){              // 通過 reader.result 來訪問生成的 base64 DataURL       var base64 = reader.result;              //打印到控制臺,按F12查看       console.log(base64);              //上傳圖片       base64_uploading(base64);            }      reader.readAsDataURL(file);          });  //AJAX上傳base64 function base64_uploading(base64Data){   $.ajax({      type: 'POST',      url: "上傳接口路徑",      data: {        'base64': base64Data      },      dataType: 'json',      timeout: 50000,      success: function(data){                  console.log(data);               },      complete:function() {},      error: function(xhr, type){          alert('上傳超時(shí)啦,再試試');                }    }); }

      其實(shí)前端的代碼也并不復(fù)雜,主要是使用了new FileReader();的接口來轉(zhuǎn)化圖片,new FileReader();還有其他的接口,想了解

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號