Click here to Skip to main content
Licence 
First Posted 30 Nov 2005
Views 60,263
Bookmarked 40 times

Testing file size before uploading it

By | 30 Nov 2005 | Article
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

About the Author

Taha Amin

Team Leader
http://www.linkdev.com/
Egypt Egypt

Member

B/OSS.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberAndrew Nefedkin5:27 29 Mar '10  
GeneralMy vote of 1 PinmemberHarishBhattbhatt18:10 22 Sep '09  
GeneralVery poor example PinmemberThree Nine Consulting11:42 15 Oct '08  
GeneralHelp Pinmemberpradeep_puru19:14 6 Sep '07  
GeneralNot the solution at all. PinPopularmemberChrisAdams10:21 2 Dec '05  
GeneralPart of the solution Pinmembersteve_hocking5:35 30 Nov '05  
GeneralRe: Part of the solution PinmemberTaha Zayed5:46 30 Nov '05  
GeneralRe: Part of the solution PinmemberDevDude5:57 30 Nov '05  
GeneralRe: Part of the solution PinmemberTaha Zayed6:01 30 Nov '05  
GeneralRe: Part of the solution PinmemberDevDude6:08 30 Nov '05  
GeneralRe: Part of the solution Pinmemberlouisa.04026:17 30 Nov '05  
GeneralRe: Part of the solution PinmemberDevDude7:05 30 Nov '05  
GeneralRe: Part of the solution PinmemberTaha Zayed19:30 30 Nov '05  

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.

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