Nginx+php upload large file solution

  
                  When using nginx to do webserver, you need to pay special attention to the client_max_body_size parameter when uploading large files. Otherwise, it will be interrupted in the request of nginx. It cannot be recorded in php.

First modify the php.ini file: Parameter setting Description file_uploads on Whether to allow the upload of files via HTTP. The default is ON. Upload_tmp_dir – The file is uploaded to the server where the temporary file is stored. If not specified, the system default temporary folder upload_max_filesize 8m will be used, which means the maximum size of the uploaded file is allowed. The default is 2M post_max_size 8m refers to the maximum value that can be received by PHP via the form POST, including all values ​​in the form. The default is 8M

Description

Generally speaking, after setting the above four parameters, uploading <=8M files is not a problem under normal network conditions, but if you want to upload > 8M large files, only the above four items are not necessarily able to pass. Unless your network really has a 100M/S upload speed, you have to continue to set the following parameters. Max_execution_time 600 Maximum time value (in seconds) per PHP page run, default 30 seconds max_input_time 600 Maximum time required to receive data per PHP page, default 60 seconds memory_limit 8m Maximum memory consumed per PHP page, default 8M

But still can't, because the webserver uses nginx, google a bit, found a parameter added in the nginx conf: The default is 1M, need to increase. Add a client_max_body_size 30m in nginx.conf;

Restart 30m to indicate the maximum upload 30M, how much to set.

Text Summary

By default, nginx allows the maximum number of individual file bytes requested by the client to be 1M, which means that if the uploaded file exceeds 1M, it will not be uploaded. You can manually modify this parameter, for example, put the following code in the http section, so you can upload files below 10M

client_max_body_size 10m; Also limit the upload file size configuration in php.ini is also configured, the default is

post_max_size = 8M upload_max_filesize = 2M

Copyright © Windows knowledge All Rights Reserved