


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
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 for each PHP page, the default is 8M
The 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)

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

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 originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

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

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment