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){
if(GetSize(ctrl.value)>10485760)
{
alert('Sorry file size > 10MB');
ctrl.form.reset();
}
}
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);".
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