By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

check clientside file size

P: n/a
hi,

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

thanks
yavuz bogazci

Jun 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rik
yo*********@googlemail.com wrote:
hi,

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

Not with PHP, which doesn't work client sided.
What is possible:
http://nl3.php.net/manual/en/features.file-upload.php
"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" />
</form>

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

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.

Grtz,
--
Rik Wasmus
Jun 23 '06 #2

P: n/a
*** yo*********@googlemail.com escribió/wrote (23 Jun 2006 04:51:41 -0700):
i have an upload mechanism on my website and want to check the filesize
on the client size. is this possible?


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
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Jun 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.