views:

89

answers:

3

when upload button clicked on page... want to check filesize selected in fileupload control and stop postback of upload button if file size exceeds... what are the ways to do this using jquery/javascript?

+1  A: 

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.

WoLpH
Not implemented by which one?
Bruno Reis
@Bruno: which one implements it?
John Saunders
@John Saunders, I have no idea, why do you ask me?
Bruno Reis
@Bruno: because you asked, "Not implemented by which one?", as though you felt it was implemented on many browsers. I wanted to know which browsers implemente it.
John Saunders
@John Saunders / @Bruno Reis: None of them support it unfortunately.Browser plugins are the only way.
WoLpH
+1  A: 

You can't, you must use server-side PHP or ASP[.NET] to do so. If it is possible, crackers will be stealing files.

SHiNKiROU
+1  A: 

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.

levik