Home  >  Article  >  Backend Development  >  How to set the size of uploaded files in PHP

How to set the size of uploaded files in PHP

墨辰丷
墨辰丷Original
2018-05-16 14:46:503233browse

This article mainly introduces how to set the size of uploaded files in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

Solution:

First:

Check the following line in php.ini:

upload_max_filesize = 8M
post_max_size = 10M
memory_limit = 20M

Also confirm the uploaded ff9c23ada1bcecdd1a0fb5d5a0f18437 Similar to the following line

<input type="hidden" name="MAX_FILE_SIZE" value="500000">

Second:

If it is apache 2, you need to modify the LimitRequestBody 524288 in

/etc/httpd/conf.d/php.conf

to make 524288 (=512×1024) larger, for example 5M (=5×1024×1024)

In addition: PHP’s maximum execution time is also a possible factor.

It can also be set temporarily through the php file. The code is as follows:

<?php
    ini_set(&#39;max_execution_time&#39;, &#39;600&#39;);
    ini_set(&#39;post_max_size &#39;, &#39;100M&#39;);  // 好像设置不成功,不起作用
    ini_set(&#39;upload_max_filesize&#39;, &#39;200M&#39;); // 好像设置不成功,不起作用
?>

Open php.ini, first find

;;;;;;;;;;;;;; ;;;
; File Uploads ;
;;;;;;;;;;;;;;;;;;

area has the following parameters that affect file upload:

  • file_uploads = on ; Switch whether to allow file uploads via HTTP. The default is ON which means open

  • upload_tmp_dir; files are uploaded to the place where temporary files are stored on the server. If not specified, the system default temporary folder will be used

  • upload_max_filesize = 200m ;Wangwen business, that is, the maximum size of the file allowed to be uploaded. The default is 2M

at

##;;;;;;;;;;;;;;;;;;;;

; Data Handling ;
; ;;;;;;;;;;;;;;;;;

area, there is another item:

  • post_max_size = 100m; refers to POST to PHP through the form The maximum value that can be received, including all values ​​in the form. The default is 8M

Generally, after setting the above four parameters, uploading files of But if you want to upload a large file >8M, it will definitely work if you only set the above four items. Unless your network really has a 100M/S upload speed, you still have to care about the following parameters:

;;;;;;;;;;;;;;;;;;;;;

; Resource Limits ;
;;;;;;;;;;;;;;;;;;;;

  • max_execution_time = 600 ;Maximum time for each PHP page to run Value (seconds), default is 30 seconds

  • max_input_time = 600; Maximum time required for each PHP page to receive data, default is 60 seconds

  • memory_limit = 8m ;The maximum memory consumed by each PHP page, the default is 8M

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

Okay, you can try it now after setting it up. Click on a 200M file to upload it

When you are listening to music, thinking about girls, or coming back from going to the toilet, the program will tell you that the upload is successful~

Test uploading 200M on this machine file successfully.

Related recommendations:

How to solve the problem that the temporary folder cannot be found when PHP uploads files

php upload In-depth file analysis

php method to upload files to a remote server

The above is the detailed content of How to set the size of uploaded files in PHP. For more information, please follow other related articles on the PHP Chinese website!

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