


Perfect solution for php unable to upload large files_PHP tutorial
The perfect solution for php unable to upload large files
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)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
