|
Posted by Rik on 06/23/06 12:50
yonthebeach@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
Navigation:
[Reply to this message]
|