PHP Класс 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);
С версии: 2.1
Автор: Paul Klimov ([email protected])
Наследование: extends yii\base\Object
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$collection file collection to be used.

Открытые методы

Метод Описание
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.

Описание методов

getBytes() публичный Метод

Alias of Download::toString method.
public getBytes ( ) : string
Результат string file content.

getChunkCursor() публичный Метод

Returns file chunks read cursor.
public getChunkCursor ( boolean $refresh = false ) : MongoDB\Driver\Cursor
$refresh boolean whether to recreate cursor, if it is already exist.
Результат MongoDB\Driver\Cursor chuck list cursor.

getChunkIterator() публичный Метод

Returns iterator for the file chunks cursor.
public getChunkIterator ( boolean $refresh = false ) : Iterator
$refresh boolean whether to recreate iterator, if it is already exist.
Результат Iterator chuck cursor iterator.

getDocument() публичный Метод

public getDocument ( ) : array
Результат array document to be downloaded.

getFilename() публичный Метод

Returns associated file's filename.
public getFilename ( ) : string | null
Результат string | null file name.

getResource() публичный Метод

Returns persistent stream resource, which can be used to read file.
public getResource ( ) : resource
Результат resource file stream resource.

getSize() публичный Метод

Returns the size of the associated file.
public getSize ( ) : integer
Результат integer file size.

setDocument() публичный Метод

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() публичный Метод

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).
Результат string | false the extracted part of file or `false` on failure

toFile() публичный Метод

Saves download to the physical file.
public toFile ( string $filename ) : integer
$filename string name of the physical file.
Результат integer number of written bytes.

toResource() публичный Метод

Note: each invocation of this method will create new file resource.
public toResource ( ) : resource
Результат resource stream resource.

toStream() публичный Метод

Saves file into the given stream.
public toStream ( resource $stream ) : integer
$stream resource stream, which file should be saved to.
Результат integer number of written bytes.

toString() публичный Метод

Returns a string of the bytes in the associated file.
public toString ( ) : string
Результат string file content.

write() публичный Метод

Alias of Download::toFile method.
public write ( string $filename ) : integer
$filename string name of the physical file.
Результат integer number of written bytes.

Описание свойств

$collection публичное свойство

file collection to be used.
public $collection