How to set the size of uploaded files in PHP

墨辰丷
Release: 2023-03-25 22:54:01
Original
3091 people have browsed it

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
Copy after login

Also confirm the uploaded

Similar to the following line

Copy after login

Second:

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

/etc/httpd/conf.d/php.conf
Copy after login

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:

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!