如何在Symfony 4中上传文件。我已经按照Symfony文档的步骤进行了操作,但不知道哪里出错了。在上传文件时出现错误,请给我一些提示。
参考链接:
https://symfony.com/doc/current/controller/upload_file.html
错误信息:
The file "" does not exist
实体
public function getBrochure()
{
return $this->brochure;
}
public function setBrochure($brochure)
{
$this->brochure = $brochure;
return $this;
}
文件上传监听器
class FileUploader
{
private $targetDirectory;
public function __construct($targetDirectory)
{
$this->targetDirectory = $targetDirectory;
}
public function upload(UploadedFile $file)
{
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move($this->getTargetDirectory(), $fileName);
return $fileName;
}
public function getTargetDirectory()
{
return $this->targetDirectory;
}
}