Home  >  Article  >  Backend Development  >  What should I do if the file uploaded by php does not take effect?

What should I do if the file uploaded by php does not take effect?

coldplay.xixi
coldplay.xixiOriginal
2020-07-29 17:44:483055browse

Solution to the problem that PHP file upload does not take effect: 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; 2. The value of [max_execution_time] must be big enough.

What should I do if the file uploaded by php does not take effect?

Solution to php upload file not taking effect:

Scenario 1: The temporary directory where files are stored during file upload must be open and 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: max_execution_time The value 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, if there is no 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.

Case 4: upload_max_filesize = 2M Set 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.

Case 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. #Such a sentence means that the maximum allowed upload is 20MB, which depends on your own situation. The location of my nginx configuration file is

/usr/local/nginx/conf/nginx.conf.

Related learning recommendations:

PHP programming from entry to proficiency

The above is the detailed content of What should I do if the file uploaded by php does not take effect?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn