Home  >  Article  >  Backend Development  >  Veterans talk about discuz implementation of uploading files in PHP_PHP tutorial

Veterans talk about discuz implementation of uploading files in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:26:49826browse

PHP is still relatively commonly used, so I studied PHP upload files and shared them with you here. I hope it will be useful to everyone. The default upload limit of PHP is a maximum of 2M. If you want to upload files exceeding this setting, you need to adjust some parameters of PHP, apache, etc.

Below, we briefly introduce some parameters involved in PHP file upload: file_uploads is a switch that allows uploading files through HTTP. The default is ON, which means upload_tmp_dir is turned on. , upload_tmp_dir is used to describe the temporary directory where files uploaded by PHP are placed. If you want to upload files, you must ensure that the server has not closed the temporary files and has write permissions on the folder. If not specified, PHP will use the system default value upload_max_filesize to allow uploaded file size. Maximum value, the default is 2Mpost_max_size

controls the maximum amount of data that PHP can receive during a 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. max_input_time limits the time in seconds to receive data through POST, GET, and PUT methods. If the application is running on a low-speed link, you need to increase this value to accommodate the more time required to receive data memory_limit In order to avoid running scripts using a large amount of system available memory, PHP allows you to define memory usage limits.

Use the memory_limit variable to specify the maximum memory capacity that a single script can use. The value of the variable memory_limit should be appropriately greater than the value of post_max_size max_execution_time. max_execution_time sets the time that PHP waits for the script to be executed before forcibly terminating the script. This time Measured in seconds. This variable is useful when the script enters an infinite loop. However, this feature can also cause the 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 prevent PHP from shutting down the script when the script is executing some important processes. For Linux hosts, it may be under /etc/httpd/conf.d/access.conf/ There is also a php.conf file, which may solve the file size limit problem of some systems.

Example of using discuz to implement PHP file upload application

The attachment function of the forum was not originally designed for file management. Due to server configuration, PHP, network and other aspects Factors that make uploading files through forums not a good solution. For those who really need to improve the conditions for uploading forum attachments, you can try to set the parameters mentioned above in php.ini to adapt to the needs of large file uploads. At the same time, don’t forget to set the attachment restrictions in the background of the forum.

At the same time, here is a configuration guide provided by some friends who have successfully uploaded large attachments through http. Of course, due to different server configurations and network conditions, it may not be applicable to your situation. There may be many The place needs to be modified according to the following: Open php.ini,

<ol class="dp-xml">
<li class="alt"><span><span>file_uploads  on  是否允许通过HTTP上传文件的开关。默认为ON即是开    </span></span></li>
<li class=""><span>upload_tmp_dir  --  文件上传至服务器上存储临时文件的地方,如果没指定就会用系统默认的临时文件夹    </span></li>
<li class="alt"><span>upload_max_filesize  8m  望文生意,即允许上传文件大小的最大值。默认为2M    </span></li>
<li class=""><span>post_max_size  8m  指通过表单POST给PHP的所能接收的最大值,包括表单里的所有值。默认为8M   </span></li>
</ol>

Generally, after setting the above four parameters, under normal network conditions, it is not a problem to upload a file of 8M, it will definitely work if you only set the above four items. Unless your network really has a 100M/S upload speed, you have to continue setting the following parameters.

<ol class="dp-xml">
<li class="alt"><span><span>max_execution_time  600  每个PHP页面运行的最大时间值(秒),默认30秒    </span></span></li>
<li class=""><span>max_input_time  600  每个PHP页面接收数据所需的最大时间,默认60秒    </span></li>
<li class="alt"><span>memory_limit  8m  每个PHP页面所吃掉的最大内存,默认8M   </span></li>
</ol>

After modifying the above parameters, you can upload large files under normal circumstances allowed by the network


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446563.htmlTechArticlePHP is still relatively commonly used, so I studied PHP upload files and shared them with you here. Hope it's useful to everyone. The default upload limit of PHP is a maximum of 2M. If you want to upload...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn