Php perfectly solves the problem of uploading large files

Source: Internet
Author: User
Tags file size file upload form post ini parse error


Open php. ini,

Parameter settings

Whether file_uploads on allows file upload over HTTP. ON is enabled by default.
Upload_tmp_dir-upload the file to the place where the temporary file is stored on the server. If this parameter is not specified, the default temporary folder will be used.
Upload_max_filesize 8 m Wangwen business, that is, the maximum file size allowed to be uploaded. The default value is 2 MB.
Post_max_size 8 m refers to the maximum value that can be received by the form POST to PHP, including all values in the form. The default value is 8 MB.
Description
Generally, after the preceding four parameters are set, uploading a file <= 8 m is not a problem under normal network conditions.
However, if you want to upload a large file larger than 8 MB, you can only set the above four items. Unless your network has a high upload speed of 100 MB/s, you must set the following parameters.

Max_execution_time 600 maximum time (in seconds) for running each PHP page. The default value is 30 seconds.
Max_input_time 600 maximum time required for receiving data on each PHP page. The default value is 60 seconds.
Memory_limit 8 m maximum memory consumed by each PHP page. The default value is 8 M.

After modifying the preceding parameters, you can upload a large volume of files as permitted by the network.

[Edit] common error types for uploading Forum files (keep summing up ...)
Warning: Unable to open' \ php2 & prime; for reading: Invalid argument in e: \ user \ web \ larksoft.net \ upload \ upfile. php on line 10
Is the reason for php's upload_tmp_dir. The specified directory must be readable and writable.

Parse error: parse error in c: \ program files \ apache group \ apache \ htdocs \ mdweb \ ftpfile \ upload. php on line 14
Parse errors are generally statements, such as ";", "", and ")".

It's done. In/etc/httpd/conf. d/php. conf, there is
<Files *. php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 524288
</Files>

Modify the LimitRequestBody.


If you are Nginx, you also need to modify the http segment in nginx. conf:

1. Modify three items in the PHP configuration file: vim/usr/local/php/etc/php. ini
(1) post_max_size = 50 M # maximum POST data acceptable to PHP
(2) upload_max_filesize = 50 M # maximum value allowed for file Upload
(3) max_execution_time = 300 # Maximum execution time of each script, in seconds (0 is not limited, it is not recommended to set 0)
2. Modify the Nginx configuration file vim/usr/local/nginx/conf/nginx. conf. (if you forget the specific location of the configuration file, you can use locate nginx. conf to find it)
(1) client_max_body_size 50 m # maximum client Upload size 50 M
3. restart PHP:/etc/init. d/php-fpm restart
4. Restart Nginx smoothly:/usr/local/nginx/sbin/nginx-s reload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.