Use the IFRAME to upload the picture, and detect the picture size (solve JS limit picture size in browser compatibility)

Source: Internet
Author: User

Use iframe to upload pictures, detect picture size:

http://perfectlife.iteye.com/blog/396959

The following JS, compatibility issues, can not be achieved:

function Checkform (obj) {
Str=obj.value.tolowercase ();
var ext=str.split (".");
var type=filetype.split (",");
for (Var i=0;i<type.length;i++) {
Alert (ext[1]+ "," +type[i]);
if (Ext[1]==type[i]) {
Bool=true;
alert (bool);
}
}
if (bool) {
var boolsize=checksize (str);
alert (boolsize);
if (Boolsize==false) {
Alert ("You upload a picture too large to exceed" +filesize+ "KB");
return false;
}
}else{
Bool=false;
Alert ("The type you upload is not one of the" +type+ ");
return false;
}
}
function Checksize (fileName) {
var img=new Image ();
IMG.SRC=STR;
fsize=img.filesize/1024;
Fsize=fsize.tofixed (1);
alert (fsize);
if (img.readystate!= "complete") {
Bool=false;
return false;
}else{
Alert (fsize+ "," +filesize);
if (fsize>filesize) {
Bool=false;
return false;
}else{
Bool=false;
return true;
}
}
}








var imgsize = 1024 * 100; Max 100K
var temp = false;
function Checkimgsize (obj) {

if (Obj.value!= "") {

Detection type
var val = obj.value;
if (/^.*?\. ( Gif|png|jpg|jpeg|bmp) $/.test (val)) {
}else{
Alert ("Only upload images in gif, PNG, JPG, BMP format");
temp = false;
return false;
}

var img = new Image ();
Img.onreadystatechange = function () {
if (img.readystate = = "complete") {
if (img.filesize <=0 | | img.filesize > Imgsize) {
Alert ("Current file size" + img.filesize/1024 + "KB, exceeding maximum limit" + imgsize/1024 + "KB");
temp = false;
return false;
}else{
temp = true;
return true;
}
}
}

Img.src = val;

}


-----to be inspected, only temporarily stored, please do not copy

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.