<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, maximum-scale=1.0, width=device-width">
<title>Image Test</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
var fileUrl,imgSuffix,imagSize;
var imgReg = /(gif|jpg|jpeg|png|tiff|GIF|JPG|JPEG|PNG|TIFF)$/;
$(document).ready(function(){
$("#uploadImg").on("change",function(){
uploadImgCheck("uploadImg",this);
});
});
function uploadImgCheck(imgId,file){
fileUrl = $("#" + imgId).val();
if(fileUrl){
//图片后缀
imgSuffix = fileUrl.substring(fileUrl.lastIndexOf(".") + 1 ).toLowerCase();
//图片大小
imagSize = file.files[0].size;
if(imgReg.test(imgSuffix)){
if(imagSize < 5*1024*1024){
var img = document.getElementById('imghead');
var reader = new FileReader();
reader.onload = function(evt){
img.src = evt.target.result;
// 图片分辨率
var imgWidth = img.offsetWidth;
var imgHeight = img.offsetHeight;
$("#imghead").css("width","70%").css("padding-left","15%");
var imageInfoTxt = "图片后缀:" + imgSuffix + "<br/>图片大小:"+ (imagSize/(1024*1024)).toFixed(3) + " M <br/>图片分辨率:" + imgWidth + " * " + imgHeight + "<br/>";
$("#imageInfo").empty().html(imageInfoTxt);
/*
if(imgWidth > 1024 || imgHeight > 768){
alert('图片分辨率1024*768 以内');
}else{
//ajaxFileUploadPic(imgId);
}*/
}
reader.readAsDataURL(file.files[0]);
}else{
alert('图片大小不能大于 5M');
}
}else{
alert('只允许上传JPG、JPEG、GIF、PNG、TIFF格式图片');
}
}
}
</script>
</head>
<body>
<span id="imageInfo"></span>
<input type="file" id="uploadImg"/>
<div id="preview">
<img id="imghead">
</div>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, maximum-scale=1.0, width=device-width">
<title>Image Test</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
var fileUrl,imgSuffix,imagSize;
var imgReg = /(gif|jpg|jpeg|png|tiff|GIF|JPG|JPEG|PNG|TIFF)$/;
$(document).ready(function(){
$("#uploadImg").on("change",function(){
uploadImgCheck("uploadImg",this);
});
});
function uploadImgCheck(imgId,file){
fileUrl = $("#" + imgId).val();
if(fileUrl){
//图片后缀
imgSuffix = fileUrl.substring(fileUrl.lastIndexOf(".") + 1 ).toLowerCase();
//图片大小
imagSize = file.files[0].size;
if(imgReg.test(imgSuffix)){
if(imagSize < 5*1024*1024){
var img = document.getElementById('imghead');
var reader = new FileReader();
reader.onload = function(evt){
img.src = evt.target.result;
// 图片分辨率
var imgWidth = img.offsetWidth;
var imgHeight = img.offsetHeight;
$("#imghead").css("width","70%").css("padding-left","15%");
var imageInfoTxt = "图片后缀:" + imgSuffix + "<br/>图片大小:"+ (imagSize/(1024*1024)).toFixed(3) + " M <br/>图片分辨率:" + imgWidth + " * " + imgHeight + "<br/>";
$("#imageInfo").empty().html(imageInfoTxt);
/*
if(imgWidth > 1024 || imgHeight > 768){
alert('图片分辨率1024*768 以内');
}else{
//ajaxFileUploadPic(imgId);
}*/
}
reader.readAsDataURL(file.files[0]);
}else{
alert('图片大小不能大于 5M');
}
}else{
alert('只允许上传JPG、JPEG、GIF、PNG、TIFF格式图片');
}
}
}
</script>
</head>
<body>
<span id="imageInfo"></span>
<input type="file" id="uploadImg"/>
<div id="preview">
<img id="imghead">
</div>
</body>
</html>