Hi All,
how can i validate the file size on the client side using javascript i am using type=file for selecting the file
Regards, hemant
Hi All,
how can i validate the file size on the client side using javascript i am using type=file for selecting the file
Regards, hemant
you cannot, javascript is not allowed to tinker with local files
You can do it in firefox like so
html:
<form action="" method="get" accept-charset="utf-8"> <input type="file" name="file" value="" id="file"> <p><input type="submit" value="Continue →"></p> </form>
javascript:
var filesize = document.forms[0].file.files[0].fileSize
if there's a way to do this in IE, I don't know it. It probably involves activeX or some other such rubbish.
edit: I found this here, HOW TO DO THIS IN IE
<head>
<script>
function getSize()
{
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.upload.file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
alert(size + " bytes");
}
</script>
</head>
<body>
<form name="upload">
<input type="file" name="file">
<input type="button" value="Size?" onClick="getSize();">
</form>
</body>
</html>
Perhaps you could use SWFUpload instead, which is a small Flash application that handles the client side of the upload for you. From their feature list: