Symfony 2文件上传。如何在move()上抛出异常

时间:2011-12-08 10:25:05

标签: file-upload symfony

阅读symfony文档,http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html

// you must throw an exception here if the file cannot be moved
// so that the entity is not persisted to the database
// which the UploadedFile move() method does automatically
$this->file->move($this->getUploadRootDir(), $this->path);

但如果我做了

if ($this->file->move(...)) 

我收到了错误

  

捕获致命错误:类别Symfony \ Component \ HttpFoundation \ File \ File的对象无法在... / xxx.php第96行中转换为布尔值

1 个答案:

答案 0 :(得分:2)