没有合适的资源?快使用搜索试试~ 我知道了~
我们可以让表单不对files表单提交的数据进动转换,我们可以在controller法中通过$request对象来获取表单提交的件,然后动的将件转换为FileMa
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86325208/bg1.jpg)
《Symfony 5全⾯开发》视频教程代码仓库:https://github.com/teebbstudios/teebblog
2021/9/29
1 / 3
我
们
查
看
⼀下
错
误
栈
代
码
,
在
P
ost
C
o
n
tro
lle
r
s
h
ow
()
⽅
法
中
,
评论表
单
对
象
会
处
理
表
单
的
请
求
,
然
后
进
⾏表
单
数据
的
转
换
。
当
表
单
处
理
到
file
s
属
性
时
,
发
现
表
单
提
交
的
数据
类
型
并
不
是
FileManaged
类
型
,
所
以
就
报
了
异常
。
我
们
可
以
让表
单
不
对
file
s
表
单
⾏
提
交
的
数据
进
⾏
⾃
动
转
换
,
我
们
可
以
在
c
o
n
tro
lle
r
⽅
法
中
通过
$
r
e
qu
e
st
对
象
来
获
取
表
单
提
交
的
⽂
件
,
然
后
⼿
动
的
将
⽂
件
转
换
为
F
ile
M
anaged
对
象
,
再
将
F
ile
M
anaged
对
象
设
置
到
评论
对
象
的
file
s
属
性
中
。
回
到
项
⽬
,
打
开
C
o
mmen
t
T
yp
e
类
,
在
file
s
表
单
⾏
中
我
们
添
加
⼀个
设
置
,
我
们
设
置
mapped
选
项
为
false
。
现
在
file
s
表
单
⾏
就
不
会
⾃
动
映
射
到
C
o
mmen
t
类
的
$
file
s
属
性
上
了
。
打
开
P
ost
C
o
n
tro
lle
r
,
在
s
h
ow
()
⽅
法
中
我
们
查
看
⼀下
表
单
提
交
的
数据
,
输
⼊
dd($data);
,
回
到
浏
览
器
刷
新
,
我
们
再
次
提
交
表
单
,
你
现
在
表
单
的
file
s
属
性
,
它
是
⼀个
空
的
A
rr
a
y
C
o
llec
t
i
o
n
对
象
。
我
们
检
查
⼀下
表
单
提
交
时
的
$
r
e
qu
e
st
对
象
。
回
到
浏
览
器
刷
新提
交
表
单
,
我
们
打
开
file
s
属
性
。
现
在
file
s
属
性
中
,
我
们
看
到
了
表
单
提
交
的
⽂
件
对
象
,
我
们
可
以
通过
$
r
e
qu
e
st
对
象
来
获
取
表
单
提
交
的
⽂
件
对
象
,
然
后
转
换
为
F
ile
M
anaged
对
象
。
回
到
代
码
,
在
表
单
提
交
的
代
码
中
,
我
们使
⽤
$
r
e
qu
e
st
对
象
的
file
s
属
性
来
获
取
所
有
上
传
的
⽂
件
对
象
。
定
义
⼀个
返
回
值
$
file
s
,
我
们
查
看
⼀下
$
file
s
变
量
,
回
到
浏
览
器
,
再
次
刷
新
,
$
file
s
变
量
是
个
数
组
,
我
们
需
要
遍
历
获
取
数
组
中
的
所
有
⽂
件
。
添
加
⼀个
f
or
循
环
,
f
or
each
$
file
s
。
第
⼀个
键
是
c
o
mmen
t
,
第
⼆
个
键
是
file
s
,
$
file
对
象
。
我
们
添
加
⼀个
注
释
,
现
在
$
file
对
象
的
类
型
是
U
p
l
o
aded
F
ile
,
再
回
到
浏
览
器
,
我
们
展
开
U
p
l
o
aded
F
ile
,
可
以
通
过
U
p
l
o
aded
F
ile
对
象
的
⽅
法
来
获
取
上
传
的
⽂
件信
息
,
然
后
将
⽂
件
移
动到
指
定
的⽬
录
中
。
回
到
代
码
,
为了
节
省
时
间
,
我
这
⾥
就
直
接
粘
贴
代
码
了
。
#src/Controller/PostController.php
class PostController extends AbstractController
{
// ...
#[Route('/post/{id1}', name: 'post_show', methods: ['GET', 'POST'])]
#[ParamConverter('post', options: ['id' => 'id1'])]
public function show(Request $request, Post $post,
EntityManagerInterface $entityManager,
PaginatorInterface $paginator, CommentRepository
$commentRepository): Response
{
$commentForm = $this->createForm(CommentType::class);
$commentForm->handleRequest($request);
if ($commentForm->isSubmitted() && $commentForm->isValid()) {
if ($commentForm->get('submit')->isClicked()) {
/**@var Comment $data * */
$data = $commentForm->getData();
$files = $request->files->all();
/**@var UploadedFile $file**/
foreach ($files['comment']['files'] as $file){
$originName = $file->getClientOriginalName();
$fileName = pathinfo(htmlspecialchars($originName),
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![avatar](https://profile-avatar.csdnimg.cn/f013ca01c6ff4a74a3a76c2d35072825_weixin_35794280.jpg!1)
养生的控制人
- 粉丝: 18
- 资源: 333
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- git使用文档(一步一步教你使用Git仓库管理代码)
- 进制转换(通用版).cpp
- linux实践之从DistroWatch排名第三的EndeavourOS转到排名第五的Manjaro工作机迁移
- Discuz模板+资讯博客课程干货+商业版(GBK+UTF)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本123.0.6292.0)
- RB308A-SOT23-5 单节锂电池保护IC 深圳市可芯电子有限公司.pdf
- Ubuntu下安装JDK
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本123.0.6291.0)
- Android基础之用Eclipse建立工程
- WZLR(2).ipynb
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0