3.2. PHP Directives Related to (Large) File Upload

Directives are used to configure the PHP engine. They are placed in PHP's configuration file php.ini. There are a number of directives that are related to file upload and they may be useful to you (very often you can stick with the default values and do not need to modify them). The following table lists the directives and provides a brief description of each of them:


PHP Directive

Brief Description

Example

file_uploads

  • It specifies if file upload is allowed in PHP.

  • The default value is On.

  • You may need to contact the administrator to make sure the file_uploads directive is set to On.

file_uploads = Off

upload_tmp_dir

  • It specifies the directory in which uploaded files will be stored temporarily.

  • It is not specified by default.

  • If it is not specified, the PHP engine will use the system default temp directory.

upload_tmp_dir = "/temp"


Here are some PHP directives that you may have to change in order to support large file upload. By default, files that are larger than 2MB will be rejected.


PHP Directive

Brief Description

Example

upload_max_filesize

  • It specifies the maximum file size (in bytes) that the PHP engine will accept.

  • The default value is 2M (2 * 1048576 bytes).

upload_max_filesize = 4096

post_max_size

  • It specifies the maximum size (in bytes) of HTTP POST data that is permitted.

  • The default value is 8M (8 * 1048576 bytes).

  • Make sure this value is greater than that of the upload_max_filesize directive.

post_max_size = 10M

memory_limit

  • It specifies the maximum amount of memory (in bytes) that is allowed for use by a PHP script.

  • The default value is 16M (16 * 1048576 bytes).

  • This value should be greater than that of the post_max_size directive.

memory_limit = 20M

max_input_time

  • It specifies the maximum amount of time (in seconds) that is allowed for each PHP script to receive the client's HTTP request.

  • The default value is 60.

  • If you need to support large file upload, you may need to increase this value to prevent timeouts.

  • Note that some users may have a slow connection. You have to take that into account.

max_input_time = 90

max_execution_time

  • It specifies the maximum amount of time (in seconds) that is allowed for each PHP script to execute.

  • The default value is 30.

  • If you need to process large uploaded files with PHP, you may need to increase this value to prevent timeouts.

max_execution_time = 60



Previous Page Page 4 of 11 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page