Link to home
Start Free TrialLog in
Avatar of jtcy
jtcy

asked on

JavaScript: Checking file size before accepting upload

I have a file upload bar for people to upload image. I am looking for a script that can pop up a window warning user that the file selected has file over the maximum file size limit. This script has to check the file size before starting to accept file upload. Is there anyway to do it?
ASKER CERTIFIED SOLUTION
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh the value <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> is file size in bytes I believe.
SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have to create an ActiceX...Try this out..
1. Make sure you use IE 5.5 and above
2. Just allow activeX by adding that page as trusted site.

<HTML>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
function check()
{
var Objfile = new ActiveXObject("Scripting.FileSystemObject");
var fileval = document.form1.TxtFile.VALUE;
var fist = objfile.getFile(fileval);
var fsize = fist.size;
alert(fsize + " bytes");
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="form1">
<INPUT TYPE="file" NAME="TxtFile">
<INPUT TYPE="button" NAME="ButCheck" VALUE="SIZE" onClick="check();">
</FORM>
</BODY>
</HTML>
ActiveX won't work in anything but IE as far as I know.

Maybe a Java Applet would provide the functionality needed and work cross browser?
Either ActiveX or Java would have to be allowed to access the local file system.
Lost of popups to click OK to
Forced accept.

Computer101
EE Admin