当前位置:网站首页>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'];
}边栏推荐
- Zhubo Huangyu: all the precious metals you want to know are here
- C generic
- Nailing open platform - applet development practice (nailing applet client)
- Getting started with flask
- After four years of outsourcing, people are directly abandoned...
- CDN with OSS acceleration
- NFT creation and binding of BSC and HT chains
- 使用Jsoup提取接口中的图片
- Knowledge about SQL - DML
- Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
猜你喜欢
![[Qunhui] import certificate](/img/1f/ab63b0556a60b98388b482d70f6156.jpg)
[Qunhui] import certificate

一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)

pip 批量完全卸载包

線程同步之讀寫鎖

The open software of win10 system is too small. How to make it larger (effective through personal test)

Unity mobile game performance optimization spectrum CPU time-consuming optimization divided by engine modules
![[QT] resource file import](/img/0f/6eff57a09edda284b833947dab16af.png)
[QT] resource file import

Threejs special sky box materials, five kinds of sky box materials are downloaded for free
![[Nuggets' operation routine disclosure] the routine of being truly Nuggets](/img/42/b4004579fc89f7efcb6b4a4bc7e389.png)
[Nuggets' operation routine disclosure] the routine of being truly Nuggets

CDN with OSS acceleration
随机推荐
English version of ternary loss
Gateway can not connect to tcp://127.0.0.1: Connection refused
In 2022, what professional competitions can college students majoring in automation, electrical engineering and automation participate in?
Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions
Review of number theory
[从零开始学习FPGA编程-45]:视野篇 - 集成电路助力数字化时代高质量发展-2-市场预测
mysql自带的性能测试工具mysqlslap执行压力测试
Video label forbids downloading. The test is valid. Hide button. The test is valid at three points
What should I do if I don't understand the precious metal indicators
But the Internet began to have a new evolution and began to appear in a new state
What are the advantages and risks of paper gold investment
Knowledge about SQL - DML
力扣 515. 在每个树行中找最大值
go语言泛型在IDE中语法报错
Group by and order by are used together
Daily tests
Detailed explanation of widget construction process of fluent
Capture packets (Wireshark)
Go SQL parsing time Time type
After a test of 25K bytes, I really saw the basic ceiling