To know file size beforehand in JS
Is it possible to get the file size of the file being submitted before the upload actually starts on Javascript开发者_如何学C?
I didn't know about this, but you can have a look at this previous post on SO:
how validate file size using HTML and Javascript on client side
No, that's not reliably possible due to security restrictions. You'll need Flash or Java Applet for this. If your intent is just to have a progress bar, have a look at Uploadify or SWFUpload
Looks like you need the not recommended activex (source: http://www.jguru.com/faq/view.jsp?EID=330134):
<html>
<head>
<script language="JavaScript">
function A()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>
The relevant feature (The HTML5? File API or what to call it) that is needed isn't fully specified yet. Mozillas implementation can be read at the mozilla developer center
精彩评论