PHP set image file upload size specific implementation method _php tutorial

Source: Internet
Author: User
Tags php file upload
PHP default upload limit is maximum 2M, want to upload more than this set of files, need to adjust PHP, Apache and other parameters

Let's briefly introduce some of the parameters involved in uploading PHP files:
File_uploads: Whether to allow the switch to upload files over HTTP, the default is on is on.
Upload_tmp_dir:upload_tmp_dir used to explain the PHP upload files placed in a temporary directory, to upload files, you have to ensure that the server does not close the temporary files and have write permissions to the folder, if not specified, PHP uses the system default values.
upload_max_filesize: The maximum number of file sizes allowed to upload, default is 2M.
post_max_size: Controls the maximum amount of data PHP can receive in a single form submission using the Post method. If you want to use PHP file upload functionality, you need to change this value to be larger than upload_max_filesize.
Max_input_time: The time to receive data by post, get, and put is limited in seconds. If your application is running on a low-speed link, you need to increase this value to accommodate the additional time it takes to receive the data.
memory_limit: PHP allows you to define memory usage limits in order to avoid running scripts that use the system's available memory heavily. The Memory_limit variable is used to specify the maximum memory capacity variable that a single script can use memory_limit the value should be appropriately greater than the value of post_max_size.
Max_execution_time:max_execution_time sets the time at which PHP waits for the script to complete before forcing the script to terminate, which is calculated in seconds. This variable is useful when the script enters an infinite loop state. However, this feature also causes the operation to fail when there is a legitimate activity that takes a long time to complete, such as uploading large files. In such cases, you must consider increasing the value of this variable to avoid PHP closing the script when the script is performing some important process.
For Linux hosts, there may also be php.conf files under/etc/httpd/conf.d/access.conf/, which may solve some system file size limitation issues.

Add the following code to the PHP upload, you can temporarily let PHP upload large files, as follows:

 
  


See if the above variables were modified successfully:

 
  


Modified in php.ini, involving a size constraint relationship of three values. So is a temporary scheme, why this can not be modified, there is a PHP operating mode is very much related, such as security mode.

Ini_set directives cannot be used in Safe mode: Max_execution_time, Memory_limit, Child_terminate.

Therefore, like post_max_size,upload_max_filesize with the following method is not modified:

Ini_set (' post_max_size ', ' 10M ');

Ini_set (' upload_max_filesize ', ' 8M ');

The correct approach 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 in httpd.conf: allowoverride all.

In the PHP documentation, it is stated that the modifiable range of upload_max_filesize is php_ini_perdir. Php_ini_perdir means that intra-domain directives can be modified in php.ini, httpd.conf, or. htaccess files. Php_ini_system Intra-domain directives can be modified in the php.ini and httpd.conf files. So upload_max_filesize with Int_set is impossible to modify. Only the modifiable range is php_ini_all and can be modified with Int_set.

method 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_cfg_var (' register_globals ')) {    $arrInfo [' onoff '] = "open";} else{    

http://www.bkjia.com/PHPjc/625808.html www.bkjia.com true http://www.bkjia.com/PHPjc/625808.html techarticle php Default upload limit is maximum 2M, want to upload more than this set of files, need to adjust PHP, Apache and other parameters we briefly introduce some of the parameters of PHP file upload: ...

  • Related Article

    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.