Navigation
This version of the documentation is archived and no longer supported. To learn how to upgrade your version of PHP Library Manual, refer to the upgrade documentation.

MongoDB\GridFS\Bucket::openDownloadStreamByName()

Definition

MongoDB\GridFS\Bucket::openDownloadStreamByName

Selects a GridFS file by its filename and opens it as a readable stream.

function openDownloadStreamByName($filename, array $options = []): resource

This method has the following parameters:

Parameter Type Description
$filename string The filename of the file.
$options array Optional. An array specifying the desired options.

The $options parameter supports the following options:

Option Type Description
revision integer

Optional. The revision of the file to retrieve. Files with the name filename will be differentiated by their uploadDate field.

Revision numbers are defined as follows:

  • 0 = the original stored file
  • 1 = the first revision
  • 2 = the second revision
  • etc…
  • -2 = the second most recent revision
  • -1 = the most recent revision
Defaults to -1 (i.e. the most recent revision).

Return Values

A readable stream resource.

Errors/Exceptions

MongoDB\GridFS\Exception\FileNotFoundException if no file was found for the selection criteria.

MongoDB\Driver\Exception\RuntimeException for other errors at the driver level (e.g. connection errors).