ThinkPHP is an excellent PHP development framework that provides rich extension functions to facilitate developers to quickly complete various needs. During development, file uploading is a common requirement. But by default, ThinkPHP upload file size is limited. So, how to modify the upload file size?
1. PHP.ini configuration modification
The first thing to note is that there is a limit on the upload file size in the PHP.ini file. Therefore, we can modify the size of the uploaded file by modifying the PHP.ini file. The specific steps are as follows:
- Search for the php.ini file on your computer and open it.
- Search for the upload_max_filesize and post_max_size parameters and modify their values to the required size. In general, the value of upload_max_filesize should be greater than or equal to the value of post_max_size. For example, if the size of the file we need to upload is 10MB, we can modify the values of upload_max_filesize and post_max_size to 10M.
- Save the file and restart Apache to take effect.
2. Modify the application configuration file
Modifying the PHP.ini file is global. If you only want to modify the upload file size in a certain application, you need to modify the ThinkPHP application configuration. document. The specific steps are as follows:
- Open the application configuration file config.php.
- Search for the upload_max_filesize and post_max_size parameters and modify their values to the required size.
'upload_max_filesize' => '10M', 'post_max_size' => '10M',
- Save the file and restart Apache to take effect.
3. Modify the verification rules in the controller
In ThinkPHP, the file type, size, etc. are generally verified when uploading files. We can also modify the controller's Validate rules to modify upload file size. The specific steps are as follows:
- Open the controller file that needs to be modified.
- Search for verification rules and modify them. For example, if the size of the file to be uploaded is 10MB, you can modify the $fileSize parameter to 10485760 (in bytes):
$validate = new \think\Validate([ 'file' => 'fileSize:10485760|fileExt:xlsx,xls', ]);
- Save the file and the uploaded file will take effect.
Summary:
Whether it is by modifying the PHP.ini configuration or modifying the application configuration file or controller verification rules, as long as you master the method of modifying the size of the uploaded file, during the subsequent development process Easily handle various file upload needs. It should be noted that increasing the size of uploaded files will also increase server pressure and risks, so please adjust carefully.
The above is the detailed content of How to modify the size of uploaded files in thinkphp. 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

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.