LiMt
LiMt

Reputation: 9

How to limit a users uploaded image size using PHP

I was wondering how would you limit an uploaded image size to 5mb using PHP & MySQL.

Upvotes: 0

Views: 703

Answers (5)

robjmills
robjmills

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

dnagirl
dnagirl

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

Eric Petroelje
Eric Petroelje

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

Danten
Danten

Reputation: 588

Use if ($_FILE['yourfile']['size'] > (1024 * 5)) or restrict php using ini_set('upload_max_filesize', '5MB');

Upvotes: 1

Andy E
Andy E

Reputation: 344575

Check out the upload_max_filesize ini directive.

Upvotes: 4

Related Questions