Use JavaScript to determine the file size

Source: Internet
Author: User
The HTML Tag contains an IMG tag that is not generally known to developers. Let's talk about its attributes first: SRC, DYNSRC, start, ALT, controls, loop, loopdelay, heatace, vspace. ... Some common attributes will not be listed, Here we will talk about the "DYNSRC" attribute: DYNSRC can be used to insert various multimedia files in the format of Wav, Avi, AIFF, AU, MP3, Ra, Ram, etc. . The URL is an audio or video file and its path, which can be a relative or absolute path.
Example:
In this way, the path of any type of file can be dynamically assigned based on DYNSRC. In JavaScript, the file size can be obtained based on The filesize attribute of the image object. . Of course, the image object also has several other attributes, such as: filecreateddate, filemodifieddate, filesize, fileupdateddate, and filters ..., Code As follows:
JavaScript code
<SCRIPT type = "text/JavaScript">
Function getfilesize (filepath)
{
VaR image = new image ();
Image. DYNSRC = filepath;
Alert (image. filesize );
}
</SCRIPT>
<Body>
<Input type = "file" name = "file" size = "30" onchange = "getfilesize (this. Value)">
</Body>
After testing, no security prompt is displayed for the file size. (The second method can be applied to the upload control)

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.