Re: uploading files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Marc Serra <mserra@xxxxxxxx>:
> Hi, i want to create a form to upload a file on a server. My problem is 
> that i want to check the filesize before sending it because if the 
> filesize is superior than 2 MB it failed and i don't want to wait for a 
> long time for uploading a file that will fail.
>
> Can you please give me a solution to check the filesize.

See:
http://php.net/features.file-upload

Basically, you need a MAX_FILE_SIZE hidden attribute in your form:
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

However, the manual goes on to say:

 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, adding the above input field is a good first step, but it's not
foolproof; you may still get some too large files uploaded that PHP will
reject after the fact.

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:matthew@xxxxxxxxxx         | http://vermontbotanical.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux