MongoGridFSFile::getResource
(PECL mongo >=1.3.0)
MongoGridFSFile::getResource — Returns a resource that can be used to read the stored file
Описание
public stream MongoGridFSFile::getResource
( void
)
This method returns a stream resource that can be used with all file functions in PHP that 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.
At most two GridFSFile chunks will be loaded in memory.
Список параметров
У этой функции нет параметров.
Возвращаемые значения
Returns a resource that can be used to read the file with
Примеры
Пример #1 MongoGridFSFile::getResource() example
<?php
$m = new Mongo;
$images = $m->my_db->getGridFS('images');
$image = $images->findOne('mongo.png');
header('Content-type: image/png;');
$stream = $image->getResource();
while (!feof($stream)) {
echo fread($stream, 8192);
}
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- Классы GridFS
- Функция MongoGridfsFile::__construct() - Create a new GridFS file
- Функция MongoGridFSFile::getBytes() - Returns this file's contents as a string of bytes
- Функция MongoGridFSFile::getFilename() - Returns this file's filename
- Функция MongoGridFSFile::getResource() - Returns a resource that can be used to read the stored file
- Функция MongoGridFSFile::getSize() - Returns this file's size
- Функция MongoGridFSFile::write() - Writes this file to the filesystem
Коментарии
Please note that the file pointer is reset on each call to get resource