JS to determine the file size and image size when uploading images

Source: Internet
Author: User

How to read the size of a picture:

First, the native input file control has a Files property, which is an array. The elements in the array have the following properties: Lastmodifieddate,name,size,type,webkitrelativepath,

  

In this case, we can detect the size. (Size in this case is byte)

1 var fileData = file.files[0]; 2 var size = filedata.size;   // Note that the number of bytes read here is 3 var false ; 4 var maxSize = max_size; 5 maxSize = maxSize * 1024x768;   // Convert to bytes 6 isallow = size <= maxSize;

– Compatibility: IE9 cannot read input file.files this property.

How to get the width and height of a picture:

1. The actual width and height of the image can be obtained by instantiating the image object and loading src.

2. Compatibility: Use filter to handle picture size control under IE.

  

  1 

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.