移动端页面如何调用手机摄像头拍照并上传图片
解决方法:
1.页面
<input type="file" accept="image/*" placeholder="点击上传" name="ipaddress" id="ipaddress" >
2.js核心代码
$(document).on('click', "#ipaddress", function () {
var this_ = $(this );
var size = (this_[0].files[0].size / 1024).toFixed(2);
//if(size <= 5120){
var img = this_[0].files[0];
var formData = new FormData();
formData.append("imgFile",img);
$.ajax({
type:"post",
url:"<?php echo ASSET_URL;?>kindeditor/php/upload_json.php",
data:formData,
cache: false,
processData : false,
contentType : false,
beforeSend: function(XMLHttpRequest){
},
success:function(data){
var msg = $.parseJSON(data);
if(msg.error==0){
var url=msg.url;
$("#ipaddress").val(url.replace("/assets/kindeditor/php/../../..",""));
this_.parent().find("img").attr("src",$("#ipaddress").val());
}else{
J.alert('提示',msg.message);
}
},
error:function(data){
alert(0);
}
});
});