The perfect solution for php.ini unable to upload large files
1. Open php.ini (it goes without saying how to open it, Baidu has a lot)
2. Find post_max_size
The maximum value for form submission. This item does not limit the size of a single uploaded file, but limits the submitted data of the entire form
The default is 8M, set it to the value you need. It is recommended to set this parameter larger than upload_max_filesize
3. Find File Uploads
Switch whether to allow file upload via http, confirm file_uploads = on
4. Find upload_tmp_dir
Files are uploaded to the server where temporary files are stored. If not specified, the system default temporary folder will be used
If the system error prompts "XXX temporary directory XXX", you need to set a valid directory for this directory. If there is no error, just ignore it
5. Find upload_max_filesize
The maximum allowed upload file size, the default is 2M, set it to the value you need. It is recommended not to exceed the post_max_size value of this parameter, because it is controlled by the post_max_size value (even if upload_max_filesize is set to 1G, and post_max_size is only set to 2M , files larger than 2M still cannot be uploaded because it is controlled by the post_max_size value)
6. If you want to upload files larger than 8M, you also need to set the following parameters:
Find max_execution_time = 600; the maximum time value (seconds) for each PHP page to run, the default is 30 seconds
max_input_time = 600; The maximum time required for each PHP page to receive data, the default is 60 seconds
Memory_limit = 8M; The maximum memory required by each PHP page, the default is 8M
Perfect solution for uploading large files using nginx
1.client_body_buffer_size Try to set it as large as possible. This is based on speed considerations. If the uploaded file always needs to be written to the disk because it is set too small, the speed will be too slow.
2. The client_body_temp_path path must have writable permissions. This is an obvious mistake. Just correct it
3.client_max_body_size sets the maximum value for uploaded files. This is based on security considerations. We believe that normal users will not or basically will not upload files that are too large.
Can be set to client_max_body_size 100m; or set this value according to your own business.
Example
nginx configuration.
The code is as follows | |||||
cd /export/servers/nginx/ conf/nginx.conf,
location / { root html; index index.html index.htm; client_max_body_size 1000m; } |
The client_max_body_size field has been added, and it doesn’t work no matter how you restart it. Later, I found the sub-configuration file in the general configuration file:
The code is as follows | |||||
sendfileon;
|
So I found the sub-configuration file and made modifications in the sub-configuration file. The configuration files are configured as follows:
代码如下 | |
server { listen 80; server_name chat.erp.360buy.com; # access_log /export/servers/nginx/logs/chat.erp.360buy.com; location / { proxy_pass http://tomcat; client_max_body_size 1000m; } } |
Use /export/servers/nginx/sbin/nginx -s reload to restart, and the problem of limited upload file size will be solved.
Sharing my solution process, I hope it will be helpful to everyone.
If it still cannot be solved, we need to see if it is a problem with the php form settings
This code is divided into two files, one is upload.html and the other is upload.php
upload.html
代码如下 | |
Among them,
Please note
This is a tag. If we want to upload files, we must specify it as multipart/form-data, otherwise the server will not know what to do.
It is worth noting that the hidden value field of the form option MAX_FILE_SIZE in the file upload.html can limit the size of the uploaded file by setting its Value.
The value of MAX_FILE_SIZE is just a suggestion for browsers, in fact it can be easily bypassed. So don't rely on this value to limit browser restrictions. In fact, the maximum upload file size in PHP settings will not be invalid. But it's better to include MAX_FILE_SIZE in the form, as it saves users the trouble of spending time waiting for a large file to be uploaded only to find out that the file is too big.
upload.php
代码如下 | |
$f=&$HTTP_POST_FILES['Myfile']; $dest_dir=’uploads’;//设定上传目录 $dest=$dest_dir.’/’.date("ymd")."_".$f['name'];//设置文件名为日期加上文件名避免重复 $r=move_uploaded_file($f['tmp_name'],$dest); chmod($dest, 0755);//设定上传的文件的属性 或者 |
The contents of the $_FILES array in the above example are as follows. We assume that the name of the file upload field is userfile (the name can be named arbitrarily)