Reputation: 9
I was wondering how would you limit an uploaded image size to 5mb using PHP & MySQL.
Upvotes: 0
Views: 703
Reputation: 18598
depends on the method of upload really. For example within a standard HTML form you could add something like:
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
There are also options from within PHP itself that can usually be controlled through .htaccess files, like this:
php_value upload_max_filesize 5M
php_value post_max_size 5M
or through ini_set() - all depends on your setup really.
Upvotes: 2
Reputation: 20456
There are a couple of ways. The quickest, but least effective is to set the MAX_FILE_SIZE size in the HTML form.
The most effective is to change the PHP ini. You need to set the following variables:
Upvotes: 1
Reputation: 60498
Check out this link for all the details, but it will depend on the MAX_FILE_SIZE for the form, the upload_max_filesize and post_max_size in php.ini. Some other parameters may come into play as well (e.g. max_input_time or memory_limit if the max file size is large enough).
Upvotes: 0
Reputation: 588
Use if ($_FILE['yourfile']['size'] > (1024 * 5))
or restrict php using ini_set('upload_max_filesize', '5MB');
Upvotes: 1