File Upload Limit in PHP (PHP configuration)

person Jason Huangfolder_openHOW-TO, PHP, Wordpresslocal_offer, , , access_time September 23, 2009

In wordpress, if you see an error message when you trying to upload a file that even though you set the upload_max_filesize to the right size, it still say exceeding the limit. That’s because post_max_size needs to be set accordinly (it has to be biggr than upload_max_filesize).

There are 2 setting key controls file upload.

upload_max_filesize and post_max_size

post_max_size has to be bigger than upload_max_filesize, because post_max_size specifies the limit of the post data (in upload, besides the file size limit, it would also include misc information in upload).

For example:
upload_max_filesize = 25M

post_max_size = 30M

Howto optimize your PHP installation to handle large file uploads.

Though PHP presents a very versatile and user friendly interface for handling file uploads, the default installation is not geared for working with files in excess of 2 Mega Bytes. This article will help you configure your PHP engine for handling such large file transfers.
The php.ini File

All the configuration settings for your installation are contained in the php.ini file. Sometimes these setting might be overridden by directives in apache .htaccess files or even with in the scripts themselves. However you cannot over ride some of the settings that effect file uploads with .htaccess directives in this way. So let’s just concentrate on the ini file.

You can call the phpinfo() function to find the location of your php.ini file, it will also tell you the current values for the following settings that we need to modify
• file_uploads
• upload_max_filesize
• max_input_time
• memory_limit
• max_execution_time
• post_max_size

The first one is fairly obvious if you set this off, uploading is disabled for your installation. We will cover the rest of the configuration settings in detail below.

upload_max_filesize and post_max_size

Files are usually POSTed to the webserver in a format known as ‘multipart/form-data’. The post_max_size sets the upper limit on the amount of data that a script can accept in this manner. Ideally this value should be larger than the value that you set for upload_max_filesize.

It’s important to realize that upload_max_filesize is the sum of the sizes of all the files that you are uploading. post_max_size is the upload_max_filesize plus the sum of the lengths of all the other fields in the form plus any mime headers that the encoder might include. Since these fields are typically small you can often approximate the upload max size to the post max size.

According to the PHP documentation you can set a MAX_UPLOAD_LIMIT in your HTML form to suggest a limit to the browser.

memory_limit
When the PHP engine is handling an incoming POST it needs to keep some of the incoming data in memory. This directive has any effect only if you have used the –enable-memory-limit option at configuration time. Setting too high a value can be very dangerous because if several uploads are being handled concurrently all available memory will be used up and other unrelated scripts that consume a lot of memory might effect the whole server as well.

max_execution_time and max_input_time
These settings define the maximum life time of the script and the time that the script should spend in accepting input. If several mega bytes of data are being transfered max_input_time should be reasonably high. You can override the setting in the ini file for max_input_time by calling the set_time_limit() function in your scripts.

Comments

  1. My partner and I stumbled over here coming from a different
    website and thought I may as well check things out.

    I like what I see so i am just following you. Look forward to going over your web page repeatedly.

  2. Great goods from you, man. I have understand your
    stuff previous to and you’re just extremely magnificent.
    I really like what you’ve acquired here, certainly like what you are saying and the way in which you say it.

    You make it enjoyable and you still take care of to keep it sensible.

    I can not wait to read far more from you. This is really a tremendous website.

  3. Muy interesante el articulo|
    Un texto mas que currado se agradece
    Su relato es muy bien elaborado
    Me encantaria ver produndizando en relacion con el
    tema
    Llevo mucho de tiempo visitando su pagina

  4. So I recommend that four your 4:00 slot, if you car engine lights and meanings don’t have to
    be replaced, which is part of Urban Furrows inside the
    ECOC.

  5. Some mailing overnight printing companies also include direct mailing postcards.
    The truth is that processing the maioling lists ahead of the production reduces unnecessary excesses by allowing you to
    see if outsourcing more to a marketng budget that is somewhat
    limited. It is not a bad thing but the fact is that there are better ways of folding
    inserts, or personalising your mail pieces can be tiresome and time-consuming so
    you maay try them as well.

  6. Water pollution in India environmental protection act 90 has assumed gigantic proportions witth industrial effluents thrown into the sea.
    Now, if you pinch off a piece of software package that will do it
    for them, said Batiuk.

  7. If some one wishes to be updated with hottest technologies
    after that he must be pay a quick visit this website and
    be up to date all the time.

  8. Hi it’s me, I am also visiting this website daily,
    this site is actually fastidious and the people are in fact sharing nice
    thoughts.

  9. This article gives clear idea for the new visitors of blogging,
    that actually how to do running a blog.

warningComments are closed.