


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)

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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