当前位置:网站首页>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'];
}边栏推荐
- College C language final exam · multiple choice questions · summary notes of mistakes and difficulties
- Nailing open platform - applet development practice (nailing applet server side)
- Knowledge of SQL - database design, backup and restore
- Use soapUI to access the corresponding ESB project
- VHDL design
- Development trend and prospect forecast report of China's financial industry 2022-2028 Edition
- MySQL index details
- [QT] dialog box
- Ten important basic principles of software debugging and testing
- Group by and order by are used together
猜你喜欢

线程同步之条件变量

SQL related knowledge - DDL

Use soapUI to access the corresponding ESB project

Mutex of thread synchronization (mutex)

How much do you make by writing a technical book? To tell you the truth, 2million is easy!

CTF serialization and deserialization

Your requirements could not be resolved

Spark - understand parquet

35岁程序员炒Luna 千万资产3天归零,网友:和赌博一样
![[geek challenge 2019] rce me](/img/92/978c54fb42391198300c76ae92893d.jpg)
[geek challenge 2019] rce me
随机推荐
MySQL's built-in performance testing tool, mysqlslap, performs stress testing
Upload script file (one sentence back door) WAF bypass (PHP)
Principle and implementation of syn cookie
Computer network high frequency interview questions
[Nuggets' operation routine disclosure] the routine of being truly Nuggets
线程同步之互斥量(互斥锁)
Matplotlib line chart, text display, win10
Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
NPM installation tutorial
Laravel access error could not be opened
Tp6 multi table Association (table a is associated with table B, table B is associated with table C, and table d)
But the Internet began to have a new evolution and began to appear in a new state
Add, delete, modify and query curd in PHP native SQL
Knowledge of SQL - database design, backup and restore
Tencent Interviewer: How did binder get its system services?
Mobile terminal pull-down loading pull-down loading data
Review of number theory
Use soapUI to access the corresponding ESB project
钉钉开放平台-小程序开发实战(钉钉小程序服务器端)
Oracle 数据泵导表