Just Host Web Hosting Help

Upload_Max_Filesize

Problem:

How do I change my upload_max_filesize?

Solution:

Summary

  • Locate the php.ini file in the folder your upload script resides in. If none exists, install a new php.ini file from the PHP config icon in cPanel.
  • Rename php.ini.default to php.ini.
  • In the php.ini file, locate the line called 'upload_max_filesize = 2M'.
  • Modify that entry to read 'upload_max_filesize = 10M', or whatever your script requires. (M = megabytes)

Extended Version:

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 is an aid to configuring PHP for handling such large file transfers.

The php.ini file contains all the configuration settings for your installation. Sometimes these setting might be overridden by directives in apache .htaccess files or even with in the scripts themselves but for the moment let's just concentrate on the ini file.

This file contains 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. Our understanding is that browsers totally ignore this directive and the only solution that can impose such a client side restriction is Rad Upload Applet

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.

Special Notes:

Apache Settings

The apache webserver has a LimitRequestBody configuration directive that restricts the size of all POST data regardless of the web scripting language in use. Some RPM installations sets limit request body to 512Kb. You will need to change this to a larger value or remove the entry altogether.

Other Options

If you expect to handle a large number of concurrent file transfers on your website consider using a perl or java server side component. PHP happens to be our favorite web programming language as well but perl is just slightly ahead when it comes to file handling.

Most installations of perl as an apache module can accept up to 32 megabytes out of the box. Compare this against the 2MB default for PHP. The downside is that perl coding takes just a bit more effort than PHP but it's worth it.

Knowledgebase Article 109,694 views bookmark tags: optimize php upload (updated 1194 days ago)


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

How do I enable PHP 5 for my PHP applications? How do I change to PHP FastCGI? How do I use a single php.ini file? (updated 33 days ago)
Knowledgebase Article 79,966 views tags: config php

How do I change the PHP environment for my site with php.ini? (updated 14 days ago)
Knowledgebase Article 190,287 views tags: configuration php server

PHP vs PHP single php.ini vs PHP with FastCGI (updated 459 days ago)
Knowledgebase Article 74,157 views tags: configuration php server

Related Help Content

How can I optimize my images? (updated 1414 days ago)
Knowledgebase Article 47,841 views tags: images optimize

Why does the FrontPage 'file upload' component not work? (updated 242 days ago)
Knowledgebase Article 54,538 views tags: frontpage page upload

The Legacy File Manager will allow you to manage almost everything about your files, you can use it to upload, download, edit the code, change permissions and more! (updated 935 days ago)
Video "How-to" Tutorial 66,722 views tags: cpanelutilities files upload

In the newer versions of PHP, they have included a new directive to control and handle remote includes. We disable this option, by default, which may affect some of your PHP scripts. (updated 1378 days ago)
Knowledgebase Article 45,035 views tags: php remote url

Which PHP PEAR Packages are installed? How can I install PHP PEAR Packages? (updated 12 days ago)
Knowledgebase Article 46,117 views tags: package pear php

How do I turn the display_errors flag on for php? (updated 1395 days ago)
Knowledgebase Article 46,059 views tags: display errors php

When creating a symlink to a php page, I get a 500 error. I am able to use symlinks to other files and folders fine. (updated 1168 days ago)
Knowledgebase Article 43,232 views tags: link php

How can I adjust the php settings specifically for an Addon Domain? (updated 396 days ago)
Knowledgebase Article 74,494 views tags: domain php