PHP cannot upload large files perfect solution _php Tutorial

Source: Internet
Author: User
Tags php form

PHP cannot upload large files perfect solution


PHP.ini cannot upload large files perfect solution

1, open php.ini (open the way it goes without saying, Baidu a lot)

2. Find Post_max_size

The form submits the maximum value, which is not limited to the size of the individual file being uploaded, but to the entire form's submission data.

The default is 8M, set to the value you need, this parameter is recommended to be set larger than upload_max_filesize

3. Find File Uploads

Allow switch to upload file via http, confirm file_uploads = On

4. Find Upload_tmp_dir

Files are uploaded to the server where temporary files are stored, and if not specified, the system default Temp folder is used

If the system error indicates that there is "xxx temp directory XXX", this directory will need you to set up a valid directory, no error, no tube

5. Find Upload_max_filesize

Allow the maximum size of the upload file, default to 2M, set to your own need for this parameter is recommended not to exceed the post_max_size value, because it is controlled by the Post_max_size value (even if upload_max_filesize set 1G, and Post_max_ When size is set to 2M only, files larger than 2M cannot be transmitted, as 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; maximum time value per php page (seconds), default 30 seconds

Max_input_time = 600; The maximum time required for each PHP page to receive data, default 60 seconds

Memory_limit = 8M; The maximum memory required for each PHP page, default 8M

The perfect solution for uploading large files by Nginx

1.client_body_buffer_size try to set the large point, which is based on the speed of consideration, if because the settings are too small, resulting in the upload of the file old to write disk, that speed is too slow.

2.client_body_temp_path path to have writable permission, this is a clear error. Just fix it, okay?

3.client_max_body_size set the maximum value of the uploaded file, this is based on security considerations, we believe that normal users will not or basically not upload too large files.

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, inside the server section of this configuration file

Location/{

root HTML;

Index index.html index.htm;

Client_max_body_size 1000m;

}

The

Adds the Client_max_body_size field and does not restart. A sub-profile was later found in the general configuration file:

code is as follows

sendfileon;
#tcp_nopush on;

#keepalive_timeout 0;
Keepalive_timeout;

#gzip on;
include domains/*;
#include domains/chat.local;
#include domains/chat.erp.com;
#include domains/support.chat.com;
#include douains/chat.com;

Server {
Listen 80;
server_name localhost;

The

then finds the sub-configuration file, which is modified in the allocation file. The sub-configuration file is configured as follows:

code as follows
server
{
Listen;
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;
}
}

With/export/servers/nginx/sbin/nginx-s reload restart, the upload file size is limited to solve the problem.

Share my solution, I hope it will be helpful to everyone.

If it still doesn't work out we need to see if it's a php form setup problem

This code is divided into two files, one for upload.html and one for upload.php

Upload.html

The code is as follows

which

Please note

This is a label, we want to implement the file upload, must be specified as Multipart/form-data, otherwise the server will not know what to do.

It is worth noting that the hidden domain value of the form option max_file_size in file upload.html can limit the size of uploaded files by setting their value.

The value of max_file_size is just a suggestion to the browser, in fact it can be simply bypassed. Therefore, do not put restrictions on the browser to hope for this value. In fact, the maximum number of uploaded files in PHP settings is not invalidated. But it's best to add max_file_size to the form because it avoids the hassle of having to wait for a large file to be uploaded before the user finds it too big.

upload.php

The code is as follows
$f =& $HTTP _post_files[' Myfile ';
$dest _dir= ' uploads ';//Set upload directory
$dest = $dest _dir. '/'. Date ("Ymd"). " _ ". $f [' name '];//set file name to date plus file name to avoid duplication
$r =move_uploaded_file ($f [' Tmp_name '], $dest);
chmod ($dest, 0755);//Set the properties of the uploaded file
Or

The contents of the $_files array in the example above are shown below. We assume that the name of the File upload field is UserFile (name can be arbitrarily named)

http://www.bkjia.com/PHPjc/898884.html www.bkjia.com true http://www.bkjia.com/PHPjc/898884.html techarticle php cannot upload large files perfect solution php.ini cannot upload large files perfect solution 1, open the php.ini (not to mention the open way, Baidu a lot) 2, find post_max_size table ...

  • 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.