PHP Class yii\mongodb\file\Upload

An Upload object is usually created by calling [[Collection::createUpload()]]. Note: instance of this class is 'single use' only. Do not attempt to use same Upload instance for multiple file upload. Usage example: php $document = Yii::$app->mongodb->getFileCollection()->createUpload() ->addContent('Part 1') ->addContent('Part 2') ... ->complete();
Since: 2.1
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Object
Show file Open project: yiisoft/yii2-mongodb Class Usage Examples

Public Properties

Property Type Description
$chunkCount file chunk counts.
$chunkSize chunk size in bytes.
$collection file collection to be used.
$document additional file document contents. Common GridFS columns: - metadata: array, additional data associated with the file. - aliases: array, an array of aliases. - contentType: string, content type to be stored with the file.
$filename filename to be used for file storage.
$length total upload length in bytes.

Public Methods

Method Description
__destruct ( ) Destructor.
addContent ( string $content ) Adds string content to the upload.
addFile ( string $filename ) Adds a file content to the upload.
addStream ( resource $stream ) Adds stream content to the upload.
cancel ( ) Cancels the upload.
complete ( ) : array Completes upload.
init ( )

Private Methods

Method Description
flushBuffer ( boolean $force = false ) Flushes [[buffer]] to the chunk if it is full.
insertChunk ( string $data ) Inserts file chunk.
insertFile ( ) : array Inserts [[document]] into file collection.

Method Details

__destruct() public method

Makes sure abandoned upload is cancelled.
public __destruct ( )

addContent() public method

This method can invoked several times before Upload::complete is called.
public addContent ( string $content )
$content string binary content.

addFile() public method

This method can invoked several times before Upload::complete is called.
public addFile ( string $filename )
$filename string source file name.

addStream() public method

This method can invoked several times before Upload::complete is called.
public addStream ( resource $stream )
$stream resource data source stream.

cancel() public method

Cancels the upload.
public cancel ( )

complete() public method

Completes upload.
public complete ( ) : array
return array saved document.

init() public method

public init ( )

Property Details

$chunkCount public property

file chunk counts.
public $chunkCount

$chunkSize public property

chunk size in bytes.
public $chunkSize

$collection public property

file collection to be used.
public $collection

$document public property

additional file document contents. Common GridFS columns: - metadata: array, additional data associated with the file. - aliases: array, an array of aliases. - contentType: string, content type to be stored with the file.
public $document

$filename public property

filename to be used for file storage.
public $filename

$length public property

total upload length in bytes.
public $length