JST determine file size

Source: Internet
Author: User
Tags file size
JST to determine file size code, do not want to use ActiveX control friends to pay attention to.

The first is to apply an implementation of an ActiveX control, such as:

JavaScript code
<script type= "text/javascript" >   
Function GetFileSize (filePath)    
{   
   var fso = new ActiveXObject ("Scripting.FileSystemObject") ;   
   Alert ("File size is:" +fso.) GetFile (FilePath). Size);   
}   
</script>   
< body>   
<input type= "file" name= "file" size= "onchange=" GetFileSize (this.value); " >   
</body> 
<script type= "Text/javascript"
Function GetFileSize ( FilePath)
{
   var fso = new ActiveXObject ("Scripting.FileSystemObject");
   alert (" The file size is: "+fso." GetFile (FilePath). Size);
}
</script>
<body>
<input type= "file" name= "file" size= "onchange=" GetFileSize ( This.value); "
</body>


This approach can be implemented and easily thought of by developers, but the only disadvantage is that there is a security hint, and of course the file name is changed to. The HTA will block out the security prompts, but it's hard to get the demand. No recommendation, no more.

Here is another way, in the HTML tag is not for the general developer "deep" knowledge of the IMG tag, first of all the attributes he has: src,dynsrc,start,alt,controls,loop,loopdelay,hspace,vspace .... There are some commonly used properties are not listed, here we say "dynsrc" this attribute: Dynsrc can be used to insert a variety of multimedia, format can be WAV, Avi, AIFF, AU, MP3, Ra, Ram and so on. The URL is an audio or video file and its path, which can be a relative path or an absolute path.

Example:

This allows us to dynamically assign a path to any type of file based on DYNSRC, and to get the file size in JavaScript based on the FileSize property of the image object itself. Of course the image object has several other attributes, such as Filecreateddate, Filemodifieddate, FileSize, fileupdateddate, Filters ..., and the code is 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= "onchange=" GetFileSize (this.value) ">
</body>
<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= "onchange=" GetFileSize (this.value) ">
</body>



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.