Click here to Skip to main content
Click here to Skip to main content
Go to top

Testing file size before uploading it

, 30 Nov 2005
Rate this:
Please Sign up or sign in to vote.
Testing file size before uploading it

Abstract

there is no way to know file size before  uploading it to your server. http://www.yahoomail.com/ uploads file then check its size if its size exceed 10 MB,  yahoo server revokes it in this way you consuming server's memory and bandwidth.that's a bad deal.

Solution

you have to write some java script code:

<P>function GetSize(file){</P><P>var fso=new ActiveXObject("Scripting.FileSystemObject");</P><P>var f=fso.getFile(file);</P><P>return fso.getFile(file).size;</P><P>}</P>
 

this function takes file name and returns file size. it uses windows embed ActiveX to get file size.

then you write another function to do calculations:

function checkFileSize(ctrl){



//check if file size is > 10 MB

if(GetSize(ctrl.value)>10485760)//10 MB=10485760 B

{

alert('Sorry file size > 10MB');

ctrl.form.reset();//file grater than 10MB then reset form

}
}

simply it takes Fileupload control reference and call  GetSize function and compare its result to 10485760(10 MB=10485760 B) if the file size exceed 10 MB,it reset form else do nothing and submit form to server.to use this function  put an html button and add this attribute to it onclick="checkFileSize(this.form.File1);".
 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Taha Amin
Team Leader http://www.linkdev.com/
Egypt Egypt
B/OSS.

Comments and Discussions

 
Questionwhat if i dont want to use ActiveXobject Pinmemberpree_kh29-Nov-12 18:39 
GeneralMy vote of 1 PinmemberMember 84911541-Jun-12 2:22 
GeneralMy vote of 1 PinmemberAndrew Nefedkin29-Mar-10 5:27 
GeneralMy vote of 1 PinmemberHarishBhattbhatt22-Sep-09 18:10 
GeneralVery poor example PinmemberThree Nine Consulting15-Oct-08 11:42 
GeneralHelp Pinmemberpradeep_puru6-Sep-07 19:14 
GeneralNot the solution at all. PinmemberChrisAdams2-Dec-05 10:21 
GeneralPart of the solution Pinmembersteve_hocking30-Nov-05 5:35 
GeneralRe: Part of the solution PinmemberTaha Zayed30-Nov-05 5:46 
GeneralRe: Part of the solution PinmemberDevDude30-Nov-05 5:57 
GeneralRe: Part of the solution PinmemberTaha Zayed30-Nov-05 6:01 
GeneralRe: Part of the solution PinmemberDevDude30-Nov-05 6:08 
GeneralRe: Part of the solution Pinmemberlouisa.040230-Nov-05 6:17 
GeneralRe: Part of the solution PinmemberDevDude30-Nov-05 7:05 
GeneralRe: Part of the solution PinmemberTaha Zayed30-Nov-05 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 30 Nov 2005
Article Copyright 2005 by Taha Amin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid