当前位置:网站首页>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'];
}边栏推荐
- OSS CDN alicloud configuration method
- Clickhouse stand alone installation
- Group by and order by are used together
- Introduction Guide to the flutterplugin plug-in in the actual combat of flutter
- Capture packets (Wireshark)
- (15) Blender source code analysis flash window display menu function
- Zhubo Huangyu: all the precious metals you want to know are here
- Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
- Tp6 controller does not exist: app\index\controller\index
- Computer network high frequency interview questions
猜你喜欢

Read / write lock for thread synchronization

A brain map to summarize the needs analysis (a supplement to the actual situation at work)

win10 系统打开的软件太小,如何变大(亲测有效)

1. foundation closing

Ubuntu installs PostgreSQL and uses omnidb to view
![[Nuggets' operation routine disclosure] the routine of being truly Nuggets](/img/42/b4004579fc89f7efcb6b4a4bc7e389.png)
[Nuggets' operation routine disclosure] the routine of being truly Nuggets

Capture packets (Wireshark)
![[QT] dialog box](/img/ca/e65a0c167a4509f7c6a241870f6a32.png)
[QT] dialog box

MapReduce execution principle record

35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling
随机推荐
CTF serialization and deserialization
What preparation should I make before learning SCM?
【掘金运营套路揭露】真心被掘金的套路....
Composer version rollback version switching
力扣 515. 在每个树行中找最大值
Go SQL parsing time Time type
Construction of art NFT trading platform | NFT mall
线程同步之读写锁
Wechat applet is bound to a dynamic array to implement a custom radio box (after clicking the button, disable the button and enable other buttons)
Capture packets (Wireshark)
解析JSON接口并批量插入到数据库中
Microsoft prohibits Russian users from downloading and installing win10/11
Which is the best embedded visual programming software? (introduction, evaluation and selection of visual programming platform) [scratch, mind+, mixly]
Nailing open platform - applet development practice (nailing applet client)
Ten important basic principles of software debugging and testing
ctf [RoarCTF 2019]easy_ calc
MySQL index details
Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
The stc-isp burning program for 51 single chip microcomputer always shows that "the target single chip microcomputer is being detected..." the cold start board does not respond
Verrouillage de lecture et d'écriture pour la synchronisation des fils