日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

html5+php调用android手机图片,html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开...

發布時間:2024/7/23 php 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5+php调用android手机图片,html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上傳圖片,圖片損壞無法打開,圖片路徑也是正確的,

function selectFileImage(fileObj) {

var file = fileObj.files['0'];

//圖片方向角 added by lzk

var Orientation = null;

if (file) {

console.log("正在上傳,請稍后...");

var rFilter = /^(image\/jpeg|image\/png)$/i; // 檢查圖片格式

if (!rFilter.test(file.type)) {

//showMyTips("請選擇jpeg、png格式的圖片", false);

return;

}

// var URL = URL || webkitURL;

//獲取照片方向角屬性,用戶旋轉控制

EXIF.getData(file, function() {

// alert(EXIF.pretty(this));

EXIF.getAllTags(this);

//alert(EXIF.getTag(this, 'Orientation'));

Orientation = EXIF.getTag(this, 'Orientation');

//return;

});

var oReader = new FileReader();

oReader.onload = function(e) {

//var blob = URL.createObjectURL(file);

//_compress(blob, file, basePath);

var image = new Image();

image.src = e.target.result;

image.onload = function() {

var expectWidth = this.naturalWidth;

var expectHeight = this.naturalHeight;

if (this.naturalWidth > this.naturalHeight && this.naturalWidth > 800) {

expectWidth = 800;

expectHeight = expectWidth * this.naturalHeight / this.naturalWidth;

} else if (this.naturalHeight > this.naturalWidth && this.naturalHeight > 1200) {

expectHeight = 1200;

expectWidth = expectHeight * this.naturalWidth / this.naturalHeight;

}

var canvas = document.createElement("canvas");

var ctx = canvas.getContext("2d");

canvas.width = expectWidth;

canvas.height = expectHeight;

ctx.drawImage(this, 0, 0, expectWidth, expectHeight);

var base64 = null;

//修復ios

if (navigator.userAgent.match(/iphone/i)) {

console.log('iphone');

//alert(expectWidth + ',' + expectHeight);

//如果方向角不為1,都需要進行旋轉 added by lzk

if(Orientation != "" && Orientation != 1){

alert('旋轉處理|'+Orientation);

switch(Orientation){

case 6://需要順時針(向左)90度旋轉

alert('需要順時針(向左)90度旋轉');

rotateImg(this,'left',canvas);

break;

case 8://需要逆時針(向右)90度旋轉

alert('需要順時針(向右)90度旋轉');

rotateImg(this,'right',canvas);

break;

case 3://需要180度旋轉

alert('需要180度旋轉');

rotateImg(this,'right',canvas);//轉兩次

rotateImg(this,'right',canvas);

break;

}

}

/*var mpImg = new MegaPixImage(image);

mpImg.render(canvas, {

maxWidth: 800,

maxHeight: 1200,

quality: 0.8,

orientation: 8

});*/

base64 = canvas.toDataURL("image/jpeg", 0.8);

}else{

if(Orientation != "" && Orientation != 1){

//alert('旋轉處理');

switch(Orientation){

case 6://需要順時針(向左)90度旋轉

alert('需要順時針(向左)90度旋轉');

rotateImg(this,'left',canvas);

break;

case 8://需要逆時針(向右)90度旋轉

alert('需要順時針(向右)90度旋轉');

rotateImg(this,'right',canvas);

break;

case 3://需要180度旋轉

alert('需要180度旋轉');

rotateImg(this,'right',canvas);//轉兩次

rotateImg(this,'right',canvas);

break;

}

}

base64 = canvas.toDataURL("image/jpeg", 0.8);

}

// var str="

";

// $(".img_add").append(str);

// uploadImage(base64);

$('#myupload').ajaxSubmit({

data:{'img':base64},

dataType: 'json',

success: function (data) {

if(data.error!='0'){

alert(data.error);

}

if(data.pic){

var pic=data.pic;

if (pic.substring(0,1)=='.'){

s=pic.substring(1);

}

var str="

";

$(".img_add").append(str);

}

},

error: function () {

alert('上傳失敗');

},

})

$("#img_add").attr("src", base64);

};

};

oReader.readAsDataURL(file);

}

}

php上傳服務器部分

public function uploadimg(){

$opensession=$this->opensession;

$path = './Public/Uploads/Friends/'.$opensession['openid']."_".$_POST['openid']."/";//上傳路徑

if (isset($_POST)) {

$img = $_POST['img'];

$img = str_replace('data:image/png;base64,', '', $img);

$img = str_replace(' ', '+', $img);

$data = base64_decode($img);

$pic_name = time() . rand(10000, 99999) . ".png" ;//圖片名稱

$pic_url = $path . $pic_name;//上傳后圖片路徑+名稱

if (file_put_contents($pic_url, $data)) { //臨時文件轉移到目標文件夾

echo json_encode(array("error"=>"0","pic"=>$pic_url,"name"=>$pic_name));

} else {

echo json_encode(array("error"=>"上傳失敗!"));

}

}

}

大神 ,請問這是什么原因

總結

以上是生活随笔為你收集整理的html5+php调用android手机图片,html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。