PHP set the image file upload size of the specific implementation method

  • 2020-10-23 20:03:10
  • OfStack

Let's briefly introduce 1 of the parameters involved in PHP file upload:

The & # 8226; file_uploads: The switch that allows files to be uploaded via HTTP. By default, ON is on.
The & # 8226; upload_tmp_dir: upload_tmp_dir describes the temporary directory in which PHP uploads files. To upload files, make sure that the server has not turned off temporary files and has write permission to the folder. If not specified, PHP USES the system default.
The & # 8226; upload_max_filesize: Maximum size allowed for uploading files. Default is 2M.
The & # 8226; post_max_size: Controls the maximum amount of data that PHP can receive in a single form submission using the POST method. If you want to use the PHP file upload function, you need to change this value to be larger than upload_max_filesize.
The & # 8226; max_input_time: Limits the time to receive data via POST, GET, and PUT in seconds. If the application is running on a low speed link, you need to increase this value to accommodate the additional time required to receive the data.
The & # 8226; memory_limit: To avoid running scripts that use a lot of system available memory, PHP allows you to define memory usage limits. The maximum memory capacity variable memory_limit, specified through the memory_limit variable, should be appropriately greater than the value of post_max_size.
The & # 8226; max_execution_time: max_execution_time sets the time in seconds that PHP waits for the script to complete execution before forcing the termination of the script. This variable is useful when the script enters an infinite loop state. However, this feature can also cause an operation to fail when there is a legitimate activity that takes a long time to complete (such as uploading a large file). In such cases, you must consider increasing the value of this variable to avoid PHP shutting down the script while it is executing some important procedure.
For linux host, possibly in/etc httpd/conf d/access conf/below with php conf file, the file may solve the problem of 1 some system file size limit.

Temporarily enable PHP to upload large files by adding the following code to PHP uploads, as follows:


<?php  
//HTTP File upload switch, default is ON That is open   
ini_set('file_uploads','ON'); 
// through POST , GET As well as PUT Method The time of receiving data is limited to 90 seconds   Default value: 60  
ini_set('max_input_time','90'); 
// The script execution time is set by default 30 Seconds to 180 seconds   
ini_set('max_execution_time', '180'); 
//Post Variables by 2M Modified to 8M , the value is changed to ratio upload_max_filesize bigger   
ini_set('post_max_size', '12M'); 
// Upload file modifications as well 8M It has something to do with this one up here, something of different size.  
ini_set('upload_max_filesize','10M');  
// The scripts that are running make heavy use of the system's available memory , Upload pictures to more than one, like the best post_max_size big 1.5 times   
ini_set('memory_limit','20M'); 
?>  

Check if the above variables were modified successfully:


<?php  
echo ini_get('file_uploads')."\n";   
echo ini_get('max_input_time')."\n";   
echo ini_get('max_execution_time')."\n";   
echo ini_get('post_max_size')."\n";   
echo ini_get('upload_max_filesize')."\n";   
echo ini_get('memory_limit')."\n";   
?> 

Modified in ES83en.ini, involves the size constraint relation of three values. Therefore, it is a temporary scheme. Why can't it be modified? The operation mode of PHP has a great relationship, such as safe mode.

The ini_set instruction cannot be used in safe mode: max_execution_time, memory_limit, child_terminate.

Therefore, like post_max_size,upload_max_filesize cannot be modified with the following method:


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

The correct approach is to use the.ES110en file:


php_value upload_max_filesize 8M  
php_value post_max_size 10M  

The premise is that the site is configured in ES115en.conf: AllowOverride All.

It is stated in the php documentation that upload_max_filesize can be modified to range PHP_INI_PERDIR. PHP_INI_PERDIR means that the in-domain directive can be modified in php.ini, httpd.conf, or.htaccess files. The PHP_INI_SYSTEM domain directive can be modified in the ES139en.ini and ES141en.conf files. So upload_max_filesize with int_set cannot be modified. Only those with a modifiable range of PHP_INI_ALL can be modified with int_set.

Method to obtain 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'] = "<font color='red'> ban </font>"; 
} 
if (get_cfg_var('register_globals')){ 
    $arrInfo['onoff'] =" Open the "; 
}else{ 
    $arrInfo['onoff'] = " Shut down "; 
} 


Related articles: