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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh the value <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> is file size in bytes I believe.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.F ileSystemO bject");
var fileval = document.form1.TxtFile.VAL UE;
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>
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.F
var fileval = document.form1.TxtFile.VAL
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?
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
Lost of popups to click OK to
Forced accept.
Computer101
EE Admin
Computer101
EE Admin