我遵循了这个指南:http://symfony.com/doc/current/reference/forms/types/file.html
并在这里测试了样本
但是,当我尝试代码时,我有一个错误:
Call to undefined method Symfony\Component\Form\Form::move()
Run Code Online (Sandbox Code Playgroud)
线路正在发生这种情况:
$form['attachment']->move($dir, $someNewFilename);
Run Code Online (Sandbox Code Playgroud)
我想知道为什么会出现这个错误?
小智 18
这不使用'Form'类,但我已成功直接从请求中检索上传:
/* @var Request */
$request = $this->getRequest();
/* @var UploadedFile */
$uploadedFile = $request->files->get('upfile'); //upfile must be the value of the name attribute in the <input> tag
if (null === $uploadedFile)
return new RedirectResponse($this->generateUrl('_upload_index'));
/* @var string*/
$filename = $uploadedFile->getPathname();
Run Code Online (Sandbox Code Playgroud)
Bou*_*uki 17
我终于找到了解决方案
该文档是错误的
代替 :
$form['attachment']->move($dir, $someNewFilename);
Run Code Online (Sandbox Code Playgroud)
它应该是 :
$form['attachment']->getData()->move($dir, $someNewFilename);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33954 次 |
| 最近记录: |