Solution to the problem that php can only upload files within 1k: 1. Find and open the php.ini configuration file; 2. Modify the values of "client_max_body_size", "upload_max_filesize" and "post_max_size".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php can only upload files within 1k what to do?
Solution to the PHP file upload limit problem:
PHP large file uploads occupy a lot of resources, so it is necessary to limit the upload size. The following are three related Parameters:
client_max_body_size upload_max_filesize post_max_size
Three error messages corresponding to the above:
Warning: POST Content-Length of 9663102 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 $_FILES['file']['error']==1 nginx错误:413 Request Entiry Too Large
client_max_body_size is used to set the upper limit of the size of the client's Request body. The file to be uploaded is in the body. body, so this parameter can be indirectly regarded as a limit on the file upload size.
nginx server determines the size of the body through the Content-Length of the request header. Exceeding the set upper limit will return error code 413 Request Entity Too Large. Setting this parameter to 0 can cancel the length limit.
Syntax: client_max_body_size size; Default: client_max_body_size 1m; Context: http, server, location
client_max_body_size can be set in http, server, and location blocks, so we can increase the size of the uploaded package for the domain name or even a request address.
php error:
Warning: POST Content-Length of 9663102 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
At this time, the uploaded file size is greater than post_max_size.
php has no warning but cannot get the uploaded file
At this time $_FILES['file']['error']==1, the reason for the error is that the size of the uploaded file is less than post_max_size but Greater than upload_max_filesize.
Knowledge point expansion:
Solution to the problem of PHP and Nginx file upload size limit
For some nginx php websites, the upload file size will be limited in many aspects , one is the limitation of nginx itself, which limits the size of the file uploaded by the client, and the other is the default settings in multiple places in the php.ini file.
So in order to solve the problem of uploading file size limit, many modifications must be made. A few places are listed below.
1. Modify the /usr/local/nginx/conf/nginx.conf file, search for client_max_body_size and set the following value to the value you want to set. For example:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /home/www/htdocs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/htdocs$fastcgi_script_name; include fastcgi_params; client_max_body_size 35m; #客户端上传文件大小设为35M client_body_temp_path /home/www/nginx_temp; #设置临时目录 }
Appendix: Nginx has an Upload component:
Upload rate, upload Body size, that is, the file may be larger when uploading?
client_max_body_size 1024M upload_limit_rate 158k
is as follows:
location /upload { upload_pass /up.php; upload_cleanup 400 404 499 500-505; #upload_store /data/app/test.local/upload_tmp; upload_store /tmp; upload_store_access user:r; client_max_body_size 1024M; upload_limit_rate 158k; upload_set_form_field "${upload_field_name}_name" $upload_file_name; upload_set_form_field "${upload_field_name}_content_type" $upload_content_type; upload_set_form_field "${upload_field_name}_path" $upload_tmp_path; upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5; upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size; upload_pass_form_field "^.*$"; #upload_pass_form_field "^pid$|^tags$|^categoryid$|^title$|^userid$|^user_id$|^is_original$|^upload_file_name$|^upload_file_content_type$|^upload_file_path$|^upload_file_md5$|^upload_file_size$"; }
2. Modify php.ini
upload_max_filesize = 8M post_max_size = 10M memory_limit = 20M max_execution_time=300 file_uploads = On #默认允许HTTP文件上传,此选项不能设置为OFF。 upload_tmp_dir =/tmp/www
When uploading large files, you will feel that the upload speed is slow. When it exceeds a certain time, an error will be reported that the script execution exceeds 30 seconds. This This is because the max_execution_time configuration option in the php.ini configuration file is causing trouble. It indicates the maximum allowed execution time (seconds) of each script, and 0 indicates no limit. You can adjust the value of max_execution_time appropriately. Setting it to 0 is not recommended.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if php can only upload files within 1k?. For more information, please follow other related articles on the PHP Chinese website!