Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the size of uploaded pictures by php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article to share with you is about php how to set the size of the upload image, Xiaobian feel quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

php How to set the upload image size: 1. Open the "php.conf" file;2. Set "ini_set ('max_input_time','90');";3. Set "ini_set ('post_max_size',' 12M');" and so on.

Operating environment: linux 5.9.8 system, PHP 7.1 version, Dell G3 computer.

PHP How to set the upload image size?

PHP How to set the upload size of image files

PHP default upload limit is a maximum of 2M, want to upload more than this setting of files, you need to adjust PHP, apache and other parameters.

Below, we briefly introduce some parameters involved in uploading PHP files:

file_uploads: whether to allow file upload via HTTP switch, the default is ON that is ON.

upload_tmp_dir: upload_tmp_dir is used to specify the temporary directory where files uploaded by PHP are placed. To upload files, make sure that the server does not close temporary files and has write permissions to folders. If not specified, PHP uses the system default values.

upload_max_filesize: Maximum file size allowed to upload, default is 2 MB.

post_max_size: Controls the maximum amount of data PHP can receive in a form submission using POST. If you want to use PHP file upload, you need to change this value to be greater than upload_max_filesize.

max_input_time: Limits the time in seconds for receiving data via POST, GET, and PUT. If the application is running on a low-speed link, you need to increase this value to accommodate the additional time required to receive data.

memory_limit: PHP allows you to define memory usage limits in order to avoid running scripts that use a lot of the system's available memory. The memory_limit variable specifies the maximum amount of memory that a single script program can use. The memory_limit variable should have a value that is appropriately larger than the post_max_size value.

max_execution_time: max_execution_time Sets the time, in seconds, PHP waits for the script to finish executing before forcing it to terminate. This variable is useful when the script enters an infinite loop. However, when there is a legitimate activity that takes a long time to complete (such as uploading a large file), this feature also causes the operation to fail. In such cases, you must consider increasing the value of this variable to avoid PHP shutting down scripts while they are performing some important process.

For linux hosts, there may be a php.conf file under/etc/httpd/conf.d/access.conf/, which may solve some system file size constraints.

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

Check whether the above variables have been modified successfully:

Modified in php.ini, size constraint relation involving three values. So it is a temporary solution, why this can not be modified, there is a PHP running mode is a great relationship, such as security mode.

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

Therefore, things like post_max_size,upload_max_filesize cannot be modified using the following methods:

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

The correct way to do this is to use the.htaccess file:

php_value upload_max_filesize 8M php_value post_max_size 10M

If the site is configured with: AllowOverride All in httpd.conf.

The php documentation states that upload_max_filesize can be modified in PHP_INI_PERDIR. PHP_INI_PERDIR means that domain directives can be modified in php.ini, httpd.conf, or. httaccess files. PHP_INI_SYSTEM directives can be modified in php.ini and httpd.conf files. So upload_max_filesize with int_set is unmodifiable. Only those whose modifiable scope is PHP_INI_ALL can be modified with int_set.

How to get the value:

if(@ini_get("file_uploads")) { $arrInfo ['fileeupload '] = "Allow-files".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{ $arrInfo ['onoff '] = "off";}

The above is how php sets the size of uploaded images. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report