jquery implements upload image and image size verification, picture preview effect code

Source: Internet
Author: User

jquery implements upload image and image size verification, picture preview effect code

jquery implements upload image and image size verification, picture preview effect code

Upload Image Verification

*/

function Submit_upload_picture () {
var file = $ (' File_c '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("The picture type must be one of the. Gif,jpeg,jpg,png")
}else{
$ (' Both_form '). action= "File!upload.action";
$ (' Both_form '). Submit ();
$ (' insert_img '). sethtml (' ");
$ (' Display_div '). SetStyle (' Display ', ' block ');
$ (' Upload_div '). SetStyle (' Display ', ' none ');
}
}

Verification of image type and size

Example Two

function Validate_edit_logo (a) {
var file = $ (' file '). Value;
if (!/. ( gif|jpg|jpeg|png|gif|jpg|png) $/.test (file)) {
Alert ("The picture type must be one of the. Gif,jpeg,jpg,png")
if (a==1) {
return false;
}
}else{
var image = new Image ();
image.src = file;
var height = image.height;
var width = image.width;
var filesize = image.filesize;
$ (' BeforeEnd '). Src=file;
$ (' div_regi_right '). SetStyle (' Display ', ' block ');
if (width>80 && height>80 && filesize>102400) {
Alert (' Please upload 80*80 pixels or images less than 100k in size ');
if (a==1) {
return false;
}
}
if (a==1) {
return true;
}
}
}

Picture preview

Example Three

function Viewimg (index) {
var name = ' uploadimg ' + index;
var Imgup = $ (name);
var Imgpath = GetPath (Imgup);
var local = Imgup.value;
var point = Local.lastindexof (".");
Determine the upload file size
var img = document.createelement ("img");
IMG.SRC = local;
var filesize = img.filesize;
Img.onload = function () {filesize=this.filesize;}
if (img.filesize>5242880) {
Alert ("The picture file is too big!") ");
return false;
}

Determine if it is a picture format
var imgname = imgup.value.substring (Imgup.value.lastindexof ("."), imgup.value.length);
Imgname = Imgname.tolowercase ();
if (imgname = ". jpg") && (imgname! = ". gif") && (imgname! = ". jpeg") && (imgname! = ". png") & & (imgname!= ". bmp")) {
Alert ("u8bf7u9009u62e9u56feu7247u6587u4ef6uff0cu8c22u8c22!");
Imgup.focus ();
Empty the value inside the file www.3ppt.com
Imgup.select ();
Document.selection.clear ();
} else {
Show pictures
document.getElementById ("Sig_preview" +index). innerHTML = " ';
}
if (index >=3) {
var cnt = index + 1;
$ ("img" + cnt). Style.display = "";
}
}

jquery implements upload image and image size verification, picture preview effect code

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.