PHP: how to set the upload size of image files _ PHP Tutorial

Source: Internet
Author: User
Tags php file upload
PHP sets the upload size of image files. PHP's default upload limit is 2 MB. to upload files that exceed this setting, you need to adjust some parameters such as PHP and apache. Next, we will briefly introduce the default PHP Upload limit of 2 MB for PHP file uploading. to upload files that exceed this limit, you need to adjust some parameters such as PHP and apache. Next, we will briefly introduce some parameters involved in php file upload:

  • File_uploads: indicates whether to allow file upload over HTTP. the default value is ON.
  • Upload_tmp_dir: upload_tmp_dir indicates the temporary directory for storing files uploaded by PHP. to upload files, ensure that the server does not have the permission to close the temporary files and write the files to the folder, if this parameter is not specified, PHP uses the default value.
  • Upload_max_filesize: maximum file size that can be uploaded. the default value is 2 MB.
  • Post_max_size: Controls the maximum data size that PHP can receive when a form is submitted using the POST method. If you want to use the php file upload function, you need to change this value to a value greater than upload_max_filesize.
  • Max_input_time: seconds are used to limit the time when data is received through POST, GET, and PUT methods. If the application's running environment is on a low-speed link, you need to add this value to adapt to the more time required to receive data.
  • Memory_limit: to avoid a large amount of memory available for running scripts, PHP allows you to define the memory usage limit. The memory_limit variable is used to specify the maximum memory capacity variable memory_limit that a single script program can use. The value of memory_limit should be greater than the value of post_max_size.
  • Max_execution_time: max_execution_time sets the time for PHP to wait for the script to be executed before the script is forcibly terminated. this time is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, when there is a legal activity that takes a long time to complete (such as uploading large files), this function will also cause operation failure. In this case, you must consider increasing the value of this variable to avoid PHP closing the script when the script is executing an important process.

For linux hosts, the php. conf file may exist under/etc/httpd/conf. d/access. conf/. This file may solve the file size restrictions of some systems.

Add the following code to the PHP Upload to temporarily enable PHP to upload large files:

   

Check whether the preceding variables have been modified successfully:

  

Modification in php. ini involves the size constraints of three values. Therefore, it is a temporary solution. the reason why this cannot be modified is that there is a great relationship between the PHP running mode, such as the security mode.

Ini_set commands cannot be used in safe mode: max_execution_time, memory_limit, and child_terminate.

Therefore, the methods like post_max_size and upload_max_filesize cannot be modified as follows:

ini_set('post_max_size','10M');  ini_set('upload_max_filesize','8M');  

The correct method is to use the. htaccess file:

php_value upload_max_filesize 8M  php_value post_max_size 10M  

The premise is that the site is configured with AllowOverride All in httpd. conf.

In the php document, the modifiable range of upload_max_filesize is PHP_INI_PERDIR. PHP_INI_PERDIR indicates that the domain commands can be modified in the php. ini, httpd. conf, or. htaccess files. Commands in the PHP_INI_SYSTEM domain can be modified in the php. ini and httpd. conf files. Therefore, upload_max_filesize cannot be modified with int_set. You can use int_set to modify the value of PHP_INI_ALL.

How to get the value:

If (@ ini_get ("file_uploads") {$ arrInfo ['fileupload'] = "allow-file ". ini_get ("upload_max_filesize "). "-form :". ini_get ("post_max_size");} else {$ arrInfo ['fileupload'] = "forbidden";} if (get_uplo_var ('register _ globals ')) {$ arrInfo ['onoff'] = "Open";} else {$ arrInfo ['onoff'] = "close ";}

Bytes. Next, we will briefly introduce a part of PHP file upload...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.