File upload Symfony2:如何检查文件输入是否为空

File upload Symfony2:如何检查文件输入是否为空,file-upload,symfony,File Upload,Symfony,我正在制作一个表单来编辑一个用户可以上传文件的实体。当他做一些编辑时,我想检查他是否上传了另一个文件,以知道我是否必须删除另一个文件。我找不到如何知道输入文件是否为空。我该怎么做 public function upload() { if (null === $this->file) { // this is the condition where you can get to know that the value of // input field is

我正在制作一个表单来编辑一个用户可以上传文件的实体。当他做一些编辑时,我想检查他是否上传了另一个文件,以知道我是否必须删除另一个文件。我找不到如何知道输入文件是否为空。我该怎么做

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);
}

检查

是否尝试使用jquery验证输入文件??jquery在这里没有用处,我需要在控制器中检查它