A Web Design Community curated by Chris Coyier

Code Snippets Gallery

Code Snippets > PHP > Increase Maximum PHP Upload Size Submit one!

Increase Maximum PHP Upload Size

Many shared hosts put very low restrictions on the size of the files that can be uploaded through PHP. But, many hosts also allow you to create your own php.ini file in the root directory of your site. This file can override some of the servers default PHP settings. If not already done simply create a php.ini file and place in the public_html directory of your site. If the server is configured correctly, after inserting this snippet the servers default max upload will be overridden. For this example it was changed to 20 megabytes.

; Maximum file size of post data that PHP will accept.
post_max_size = 20M

; Maximum allowed file size for uploaded files.
upload_max_filesize = 20M

3 Responses

  1. Roflo says:

    You can see what’s your current limit by using the ini_get function:

    http://www.php.net/manual/en/function.ini-get.php

    Note that ini_set can’t be used to modify the max size of the upload files because the file info is sent before ini_set is executed.

    See:
    http://www.php.net/manual/en/function.ini-set.php#22264

  2. Thomas says:

    I am on a shared host (fused network). There default php max upload size is 12 mega bytes. After using this snippet I have successfully uploaded uploaded files through my site (running on Drupal) larger than twelve megs. Seems to work for me.

  3. Ant says:

    Hm, I hope this is not considered as cheating.

Leave a Comment

Remember:
  • Be nice.
  • Wrap multiline code in <pre> and <code> tags and escape it first (turn <'s into &lt;'s).
  • You may use regular HTML stuff like <a href="">, <em>, and <strong>
* This website may or may not contain any actual CSS or Tricks.