<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
<script type="text/javascript" src="./js/lrz.mobile.min.js"></script>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>
<body class="upload">
<form id="form">
<div id="img_show"></div>
<div id="upload">
<div id="img_file"><input type="file" accept="image/*" ><div class="btn">选择图片</div></div>
</div>
<input type="submit" class="tijiao" value="提交">
</form>
</body>
<script type="text/javascript">
var img;
$("input:file").change(function (){
//console.log(this.files[0]);
lrz(this.files[0],{width:640,quality:0.9},function(rst){
img = rst.base64;
var html = [];
var show_img = new Image();
show_img.src = rst.base64;
$("#img_show").html("<div class='upimg'></div>");
$(".upimg").html(show_img);
});
});
$("#form").submit(function (){
var phone = $("input[name='phone']").val();
var month = $("input[name='month']").val();
$.post("upload.php",{img:img,phone:phone,month:month},function(data){
img = null;
alert(data.msg);
},'json');
return false;
});
</script>
</html>
<script type="text/javascript">
var img;
$("input:file").change(function (){
//console.log(this.files[0]);
lrz(this.files[0],{width:640,quality:0.9},function(rst){
img = rst.base64;
var html = [];
var show_img = new Image();
show_img.src = rst.base64;
$("#img_show").html("<div class='upimg'></div>");
$(".upimg").html(show_img);
});
});
$("#form").submit(function (){
var phone = $("input[name='phone']").val();
var month = $("input[name='month']").val();
$.post("upload.php",{img:img},function(data){
img = null;
alert(data.msg);
},'json');
return false;
});
</script>
function error($msg=''){
$return = array('msg'=>$msg);
echo json_encode($return);
exit();
}
function main(){
if(!$_POST['img']){
error('请上传图片!');
}
$img = $_POST['img'];
$path = './upload/';
$type_limit = array('jpg','jpeg','png');
if(preg_match('/data:s*image/(w+);base64,/iu',$img,$tmp)){
if(!in_array($tmp[1],$type_limit)){
error('图片格式不正确,只支持jpg,jpeg,png!');
}
}else{
error('抱歉!上传失败,请重新再试!');
}
$img = str_replace(' ','+',$img);
$img = str_replace($tmp[0], '', $img);
$img = base64_decode($img);
$file = $path.time().'.'.$tmp[1];
if(!file_put_contents($file,$img)){
error('上传图片失败!');
}else{
error('恭喜您!上传成功!');
}
}
main();
$img = str_replace(' ','+',$img);
$img = str_replace($tmp[0], '', $img);
$img = base64_decode($img);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有