当前位置:网站首页>Tp6 is easy to tread [original]
Tp6 is easy to tread [original]
2022-06-26 04:20:00 【Telkobe】
I am going to change the framework of the website from tp5 Switch to tp6, There are many small pits in the process , File uploading is one of them
First tp6 File upload is relative to tp5 In terms of the implementation process, the difference is still large , So I didn't succeed in trying to be lazy .
If the original code is uploaded in a similar way , Then you can continue to use , Basically, there is no need to change it .
$file = request()->file('pic');
$info = $file->move($path,' file name ');The main reason is that there is a big difference when uploading and verifying .tp5 File objects have validation methods , and tp6 The unified verifier verification is adopted , So in the past, this kind of writing was used in tp6 Do not apply .
$file->validate(['size'=>500000,'ext'=>'jpg,png,gif'])->move($path);Put a paragraph below tp6 Official manual file upload verification code .
public function upload(){
// Gets the form upload file
$files = request()->file();
try {
validate(['image'=>'filesize:10240|fileExt:jpg|image:200,200,jpg'])
->check($files);
$savename = [];
foreach($files as $file) {
$savename[] = \think\facade\Filesystem::putFile( 'topic', $file);
}
} catch (\think\exception\ValidateException $e) {
echo $e->getMessage();
}}I copied this paragraph and tested it to be useless , If you copy the past , Then the result of the request will always be prompted :image Rule error , The last trace code found was filesize The name of the verification method in the verifier is fileSize, And it is precisely because of this that the corresponding error message should be returned when the error prompt is finally returned, but the default rule prompt array in the class ($this->typeMsg) Can't find filesize Corresponding value , So skip to the last prompt for rule error .

So the filesize Change to fileSize That's all right. . Some friends may not be used to try catch How to write it , Here I put my own writing .
$file = request()->file(' File domain field name ');
$v=\validate([' File domain field name '=>'fileSize:500000|fileExt:jpg,png,gif'])->failException(false);
if($v->check([' File domain field name '=>$file])){
$name=Filesystem::putFile($path,$file);
echo $name
}else{
echo $v->getError();
}Helper functions input By default, there are no filter settings , So it's using input It needs to be set manually to obtain the data transmitted from the client input The third parameter of ( How to filter data ), Can be in app\Request Object filter Global filter properties ,app Under the table of contents Request file , Instead of applying profile settings , This is different from the previous version .
namespace app;
class Request extends \think\Request{
protected $filter = ['htmlspecialchars'];
}边栏推荐
- Mobile terminal pull-down loading pull-down loading data
- 微软禁止俄用户下载安装Win10/11
- Use soapUI to access the corresponding ESB project
- Detailed explanation of widget construction process of fluent
- Install dbeaver and connect Clickhouse
- 35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
- Ipvs0 network card of IPVS
- CTF PHP audit bypasses filtering learning from topics
- Read / write lock for thread synchronization
- MySQL index details
猜你喜欢

Oracle technology sharing Oracle 19.14 upgrade 19.15

After four years of outsourcing, people are directly abandoned...

钉钉开放平台-小程序开发实战(钉钉小程序服务器端)
![ctf [RoarCTF 2019]easy_ calc](/img/c7/16adb8e4b64a4be2129a6c53c5aaa7.jpg)
ctf [RoarCTF 2019]easy_ calc

The statistics in the MySQL field become strings, and then they are converted into numbers for sorting
![[Qunhui] this suite requires you to start PgSQL adapter service](/img/fb/1aea7eb833afc1a24531b612a98400.jpg)
[Qunhui] this suite requires you to start PgSQL adapter service

NPM installation tutorial

SQL related knowledge - DDL

微软禁止俄用户下载安装Win10/11

Mutex of thread synchronization (mutex)
随机推荐
[QT] resource file import
Using jsup to extract images from interfaces
win10 系统打开的软件太小,如何变大(亲测有效)
But the Internet began to have a new evolution and began to appear in a new state
Mobile terminal pull-down loading pull-down loading data
Construction of art NFT trading platform | NFT mall
I/o virtualization technology - UIO framework
Analysis report on development status and future trend of CMOS image sensor industry in China 2022 ~ 2028
Ubuntu installs PostgreSQL and uses omnidb to view
Resolve PHP is not an internal or external command
Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr
How do wechat applets delay? Timing? Execute a piece of code after? (kengji)
Install dbeaver and connect Clickhouse
Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions
[Qunhui] this suite requires you to start PgSQL adapter service
Tp6 controller does not exist: app\index\controller\index
CDN with OSS acceleration
Nailing open platform - applet development practice (nailing applet server side)
Gateway can not connect to tcp://127.0.0.1: Connection refused
[Nuggets' operation routine disclosure] the routine of being truly Nuggets