我正在制作一个表单来编辑用户可以上传文件的实体。当他进行一些编辑时,我想检查他是否上传了另一个文件以了解我是否必须删除另一个。我找不到如何知道输入文件是否为空。我怎么能这样做?
答案 0 :(得分:0)
public function upload()
{
if (null === $this->file) {
// this is the condition where you can get to know that the value of
// input field is null or not
}
// if there is an error when moving the file, an exception will
// be automatically thrown by move(). This will properly prevent
// the entity from being persisted to the database on error
$this->file->move($this->getUploadRootDir(), $this->path);
unset($this->file);
}