PHP Class yii\mongodb\file\Download

A Download object is usually created by calling [[Collection::get()]] or [[Collection::createDownload()]]. Usage example: php Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->toFile('/path/to/file.dat'); You can use Download::substr() to read a specific part of the file: php $filePart = Yii::$app->mongodb->getFileCollection()->createDownload($document['_id'])->substr(256, 1024);
Since: 2.1
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Object
Afficher le fichier Open project: yiisoft/yii2-mongodb Class Usage Examples

Méthodes publiques

Свойство Type Description
$collection file collection to be used.

Méthodes publiques

Méthode Description
getBytes ( ) : string Alias of Download::toString method.
getChunkCursor ( boolean $refresh = false ) : MongoDB\Driver\Cursor Returns file chunks read cursor.
getChunkIterator ( boolean $refresh = false ) : Iterator Returns iterator for the file chunks cursor.
getDocument ( ) : array
getFilename ( ) : string | null Returns associated file's filename.
getResource ( ) : resource Returns persistent stream resource, which can be used to read file.
getSize ( ) : integer Returns the size of the associated file.
setDocument ( array | MongoDB\BSON\ObjectID $document ) Sets data of the document to be downloaded.
substr ( integer $start, integer $length ) : string | false Return part of a file.
toFile ( string $filename ) : integer Saves download to the physical file.
toResource ( ) : resource Returns an opened stream resource, which can be used to read file.
toStream ( resource $stream ) : integer Saves file into the given stream.
toString ( ) : string Returns a string of the bytes in the associated file.
write ( string $filename ) : integer Alias of Download::toFile method.

Method Details

getBytes() public méthode

Alias of Download::toString method.
public getBytes ( ) : string
Résultat string file content.

getChunkCursor() public méthode

Returns file chunks read cursor.
public getChunkCursor ( boolean $refresh = false ) : MongoDB\Driver\Cursor
$refresh boolean whether to recreate cursor, if it is already exist.
Résultat MongoDB\Driver\Cursor chuck list cursor.

getChunkIterator() public méthode

Returns iterator for the file chunks cursor.
public getChunkIterator ( boolean $refresh = false ) : Iterator
$refresh boolean whether to recreate iterator, if it is already exist.
Résultat Iterator chuck cursor iterator.

getDocument() public méthode

public getDocument ( ) : array
Résultat array document to be downloaded.

getFilename() public méthode

Returns associated file's filename.
public getFilename ( ) : string | null
Résultat string | null file name.

getResource() public méthode

Returns persistent stream resource, which can be used to read file.
public getResource ( ) : resource
Résultat resource file stream resource.

getSize() public méthode

Returns the size of the associated file.
public getSize ( ) : integer
Résultat integer file size.

setDocument() public méthode

Document can be specified by its ID, in this case its data will be fetched automatically via extra query.
public setDocument ( array | MongoDB\BSON\ObjectID $document )
$document array | MongoDB\BSON\ObjectID document raw data or document ID.

substr() public méthode

Return part of a file.
public substr ( integer $start, integer $length ) : string | false
$start integer reading start position. If non-negative, the returned string will start at the start'th position in file, counting from zero. If negative, the returned string will start at the start'th character from the end of file.
$length integer number of bytes to read. If given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of file). If given and is negative, then that many characters will be omitted from the end of file (after the start position has been calculated when a start is negative).
Résultat string | false the extracted part of file or `false` on failure

toFile() public méthode

Saves download to the physical file.
public toFile ( string $filename ) : integer
$filename string name of the physical file.
Résultat integer number of written bytes.

toResource() public méthode

Note: each invocation of this method will create new file resource.
public toResource ( ) : resource
Résultat resource stream resource.

toStream() public méthode

Saves file into the given stream.
public toStream ( resource $stream ) : integer
$stream resource stream, which file should be saved to.
Résultat integer number of written bytes.

toString() public méthode

Returns a string of the bytes in the associated file.
public toString ( ) : string
Résultat string file content.

write() public méthode

Alias of Download::toFile method.
public write ( string $filename ) : integer
$filename string name of the physical file.
Résultat integer number of written bytes.

Property Details

$collection public_oe property

file collection to be used.
public $collection