What should I do if php cannot upload large files?
Solution to the problem that PHP cannot upload large files: 1. Open the temporary directory where files are stored when uploading files; 2. Increase the value of max_execution_time; 3. Modify file_uploads to on; 4. Set the size of file uploads. Maximum value; 5. Increase the post_max_size value and so on.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
Reasons and reasons why php fails to upload large files Coping strategy
Why uploading large files always fails, but there is no problem uploading small files. The editor couldn't figure it out, so I searched the Internet for the reason, and compiled an article about the reasons and solutions for PHP's failure to upload large files, and shared it with everyone.
The following are various reasons and solutions:
Case 1: The temporary directory where the file is stored when uploading the file must be open and a directory writable by the PHP process owner user . If not specified PHP uses the system default.
The upload_tmp_dir in the php.ini file is used to describe the temporary directory where files uploaded by PHP are placed. If you want to upload files, you must ensure that the server has not closed the temporary file and has write permission to the folder.
Case 2: The value of max_execution_time must be large enough. The variable max_execution_time sets the time, measured in seconds, that PHP waits for the script to complete before forcefully terminating it. This variable is useful when the script enters an infinite loop. However, this feature can also cause the operation to fail when there is a legitimate activity that takes a long time to complete (such as uploading a large file). In such cases, you must consider increasing the value of this variable to prevent PHP from shutting down the script while the script is performing some important process, such as setting it to 90 seconds.
max_execution_time = 90
Note that there is also a set_time_limit function in the php function, which has the same effect as the above setting. The difference between the two is that the above is set in the php.ini file, while set_time_limit is written in php file. Therefore, you can also set the maximum execution time of the program by using set_time_limit on the page. For example, without limit: set_time_limit(0);
The third case: file_uploads = On. The default value is on, means to allow file upload via HTTP, this option cannot be set to OFF.
The 4th case: upload_max_filesize = 2M sets the maximum size of file upload. The default file upload size in the php.ini configuration file is 2M, which is easy for PHP beginners to make. One mistake is to specify the size of the uploaded file when writing the file upload function by setting the form area for the maximum size of the uploaded file, that is, the maximum value of the file allowed to be uploaded, and the value of max_file_size (hidden value field). In fact, generally others can bypass this value. , so for safety reasons, it is best to configure the upload_max_filesize option in the php.ini configuration file to set the size of the file upload. The default upload_max_filesize = 2M, that is, the file upload size is 2M. If you want to upload files exceeding 8M, such as 20M, you must set upload_max_filesize = 20M.
Scenario 5: post_max_size This value must also be large enough. This variable is also a variable related to form submission. It limits the maximum amount of data that the PHP program can receive when the client submits a form through the POST method. In general, this value can be set slightly larger than upload_max_filesize. For example, if you want to upload a 20MB file, this value can be set to 21MB.
Case 6: max_input_time This variable can limit the time of receiving data through POST, GET and PUT in seconds. If the application is running in an environment with a slow network, you need to increase this value to increase the time required to receive data, for example, set this value to 90 seconds.
max_input_time = 90
Case 7: memory_limit must also be large enough. In order to avoid running scripts from using a large amount of system available memory, PHP allows defining memory usage limits. Use the memory_limit variable to specify the maximum memory capacity that a single script can use. The value of the variable memory_limit should be appropriately larger than the value of post_max_size.
Scenario 8: In addition, if your host is an nginx operating system, if the above operations fail, remember to add client_max_body_size 20m; in the nginx configuration file. This sentence means that the maximum allowed upload is 20MB. , depending on your own situation. The location of my nginx configuration file is /usr/local/nginx/conf/nginx.conf.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if php cannot upload large files?. For more information, please follow other related articles on the PHP Chinese website!

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 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
