check clientside file size

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

i have an upload mechanism on my website and want to check the filesize
on the client size. is this possible?

yavuz bogazci

Re: check clientside file size wrote:
Quoted text here. Click to load it

Not with PHP, which doesn't work client sided.
What is possible:
"Example 38-1. File Upload Form

A file upload screen can be built by creating a special form which looks
something like this:

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />

The __URL__ in the above example should be replaced, and point to a PHP

The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file
input field, and its value is the maximum filesize accepted. This is an
advisory to the browser, PHP also checks it. Fooling this setting on the
browser side is quite easy, so never rely on files with a greater size being
blocked by this feature. The PHP settings for maximum-size, however, cannot
be fooled. This form element should always be used as it saves users the
trouble of waiting for a big file being transferred only to find that it was
too big and the transfer failed."

So, always check is server-sided. You can hint to the user what the maximum
allowed size is, they can choose to ignore it.

Rik Wasmus

Re: check clientside file size

*** escribió/wrote (23 Jun 2006 04:51:41 -0700):
Quoted text here. Click to load it

In general, it's impossible to do so with pure HTML. You'd need a signed
Java applet or similar complicate solutions. Also, I believe you can also
do it with JavaScript, but never tested it myself.

-+ Álvaro G. Vicario - Burgos, Spain
++ es mi sitio para programadores web
+- es mi web de humor libre de cloro

Site Timeline