Input type= ' file ' upload file to determine whether the size of the picture is qualified with WITDH and height

Source: Internet
Author: User

Function Checkfiles (obj) {
var array = new Array (' GIF ', ' jpeg ', ' png ', ' jpg '),////file type that can be uploaded
if (Obj.value = = " {
Alert ("Let's Select a picture to upload!");
return false;
}
Else {
var filecontenttype = Obj.value.match (/^ (. *) (\) (. {1,8}) $/) [3]; This file type is useful:)
var isexists = false;
//$ ("#img"). attr ("src", obj.value)
var fileInput = $ ("#logo") [0];
B Ytesize = fileinput.files[0].size;
//var size = Math.ceil (bytesize/1024);/* Used to determine the size of the image */
//var twidthheight = Testwidthheight (fileInput);
for (v Ar i in array) {
if (filecontenttype.tolowercase () = = Array[i].tolowercase ()) {
Isexists = true;
}
}
if (isexists = = False) {
Obj.value = null;
Alert ("The Upload picture type is incorrect!");
return false;
}
/* Determine if the size of the picture is qualified */
Testwidthheight (fileInput, obj);
}
}

function testwidthheight (file, obj) {
var isallow = false;
var max_width = "291";
var max_height = "77";
if (File.files && file.files[0]) {
var fileData = file.files[0];

Reading picture data
var reader = new FileReader ();

Reader.onload = function (e) {
var data = E.target.result;
Load picture to get the true width and height of the picture
var image = new Image ();
Image.onload = function () {
var width = image.width;
var height = image.height;
Isallow = width >= max_width && height >= max_height;
Console.log (width >= max_width);
Console.log (height >= max_height);
PD (Isallow, obj);
};
IMAGE.SRC = data;
};
Reader.readasdataurl (FileData);

} else {
//ie use filters to handle picture size control
//file name in IE is the full picture local path
var input = $ ("#logo") [0];
//var input = UPLOADER.G ET (' target '). All (' input '). Getdomnode ();
Input.select ();
//Ensure that IE9 does not occur because of a security issue that prevents Access
Input.blur ();
var src = document.selection.createRange (). text;
var img = $ (' & Lt;img style= "Filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingmethod=image); width:300px; Visibility:hidden, "/>"). AppendTo (' body '). Getdomnode ();
Img.filters.item (' DXImageTransform.Microsoft.AlphaImageLoader '). src = src;
var width = img.offsetwidth;
var height = img.offsetheight;
$ (IMG). Remove ();
Isallow = width >= max_width && height >= max_height;
PD (Isallow, obj);
}

}
var tishi=$ ("#tishi");
function PD (o, obj) {
if (o) {
Obj.value = null;
$ ("#tishi"). Text ("The picture exceeds the limit size upload failed");
$ ("#tishi"). CSS ("Color", "red");
} else {
Console.log ("0000");
$ ("#tishi"). Text ("Upload succeeded");
$ ("#tishi"). CSS ("Color", "green");
}
}

Input type= ' file ' upload file to determine whether the size of the picture is qualified with WITDH and height

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.