手機壓縮圖片透過base64 上傳 ajax不能post

來源:互聯網
上載者:User
手機壓縮圖片通過base64 上傳 ajax不能post






測試上傳檔案


















$base64=file_get_contents("php://input"); //擷取輸入資料流
$base64=json_decode($base64,1);
$data = $base64['base64'];
preg_match("/data:image\/(.*);base64,/",$data,$res);
$ext = $res[1];
if(!in_array($ext,array("jpg","jpeg","png","gif"))){
echo json_encode(array("error"=>1));die;
}
$file=time().'.'.$ext;
$data = preg_replace("/data:image\/(.*);base64,/","",$data);
if (file_put_contents('../uploadFiles/'.$file,base64_decode($data))===false) {
echo json_encode(array("error"=>1));
}else{
echo json_encode(array("error"=>0,'src'=>'../uploadFiles/'.$file));

}



這段代碼上傳到ubuntu上安卓4.4手機訪問有問題,pc端沒有問題。自己電腦win,手機、pc都沒有問題。
xhr.send(JSON.stringify(data)); // 發送base64
根本沒有post資料。
------解決思路----------------------
只要有一種用戶端能夠上傳成功,就表示代碼沒有大問題。有的只是相容性問題
既然已經使用了 jQuery,那為何不使用它提供的 ajax?至少相容性工作他已替你做好了
------解決思路----------------------
同意版主

你在安卓瀏覽器上測試的時候就會發現這個不是個例 有些是因為封了上傳


------解決思路----------------------
直接使用jquery吧,這樣可以更好解決相容問題。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.