MongoGridFSFile
在线手册:中文  英文

MongoGridFSFile::getResource

(PECL mongo >=1.3.0)

MongoGridFSFile::getResourceReturns 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. 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

范例

Example #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($stream8192);
}
?>

MongoGridFSFile
在线手册:中文  英文

用户评论:

chuck at manchuck dot com (2013-02-15 12:28:54)

Please note that the file pointer is reset on each call to get resource

Jeremy Mikola (2012-08-28 16:13:01)

This method is implemented as of version 1.3.0-beta1.
http://pecl.php.net/package-info.php?package=mongo&version=1.3.0beta1

Kon (2012-07-10 20:51:03)

This function is not implemented yet, as I get the following error every time I try to use this function:
PHP Fatal error: Call to undefined method MongoGridFSFile::getResource()
I understand it says ((o version information available, might only be in SVN) at the top, but just giving people a heads up.

易百教程