How do I validate the size of a file using JavaScript?
when upload button clicked on page... want to check filesize selected in fileuploa开发者_开发百科d control and stop postback of upload button if file size exceeds... what are the ways to do this using jquery/javascript?
Although it's hardly a foolproof way, some browser check if you have a hidden input element specifying the maximum filesize like so:
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
[edit]It seems that this type of checking was never actually implemented by one of the main browsers. It was merely hoped that they did.
In that case you can only limit the file upload size (clientside) with flash, silverlight, java or some other clientside plugin.
You can't, you must use server-side PHP or ASP[.NET] to do so. If it is possible, crackers will be stealing files.
There is no way to implement this in a pure Javascript solution, since for security reasons, Javascript doesn't have access to your local filesystem. The only fool-proof way to do what you want is on the server. Depending on the technology you use, you may be able to intercept the request while it's still being sent and kill it based on the Content-length
header.
精彩评论