public function getFileResource()
    {
        $file = $this->getAttribute('file');
        if (empty($file) && !$this->getIsNewRecord()) {
            $file = $this->refreshFile();
        }

        if (empty($file)) {
            throw new InvalidParamException('There is no file associated with this object.');
        } elseif ($file instanceof Download) {
            return $file->getResource();
        } elseif ($file instanceof UploadedFile) {
            return fopen($file->tempName, 'r');
        } elseif (is_string($file)) {
            if (file_exists($file)) {
                return fopen($file, 'r');
            }
            throw new InvalidParamException("File '{$file}' does not exist.");
        }

        throw new InvalidParamException('Unsupported type of "file" attribute.');
    }
public function getFileResource()
    {
        $file = $this->getAttribute('file');
        if (empty($file) && !$this->getIsNewRecord()) {
            $file = $this->refreshFile();
        }

        if (empty($file)) {
            throw new InvalidParamException('There is no file associated with this object.');
        } elseif ($file instanceof Download) {
            return $file->getResource();
        } elseif ($file instanceof UploadedFile) {
            return fopen($file->tempName, 'r');
        } elseif (is_string($file)) {
            if (file_exists($file)) {
                return fopen($file, 'r');
            }
            throw new InvalidParamException("File '{$file}' does not exist.");
        }

        throw new InvalidParamException('Unsupported type of "file" attribute.');
    }
public function getFileResource ( ) { $ file = $ this -> getAttribute ( 'file' ) ; if ( empty ( $ file ) && ! $ this -> getIsNewRecord ( ) ) { $ file = $ this -> refreshFile ( ) ; } if ( empty ( $ file ) ) { throw new InvalidParamException ( 'There is no file associated with this object.' ) ; } elseif ( $ file instanceof Download ) { return $ file -> getResource ( ) ; } elseif ( $ file instanceof UploadedFile ) { return fopen ( $ file -> tempName , 'r' ) ; } elseif ( is_string ( $ file ) ) { if ( file_exists ( $ file ) ) { return fopen ( $ file , 'r' ) ; } throw new InvalidParamException ( "File '{$file}' does not exist." ) ; } throw new InvalidParamException ( 'Unsupported type of "file" attribute.' ) ; }
This method returns a stream resource that can be used with all file functions in PHP,
which deal with reading files. The contents of the file are pulled out of MongoDB on the fly,
so that the whole file does not have to be loaded into memory first.
@return resource file stream resource.
@throws \yii\base\InvalidParamException on invalid file attribute value.
This method returns a stream resource that can be used with all file functions in PHP which deal with reading files . The contents of the file are pulled out of MongoDB on the fly so that the whole file does not have to be loaded into memory first .