略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoGridFSFile::getResource

2024-05-15

MongoGridFSFile::getResource

(PECL mongo >=1.3.0)

MongoGridFSFile::getResourceReturns a resource that can be used to read the stored file

说明

public MongoGridFSFile::getResource ( void ) : resource

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

范例

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);
}
?>
add a note add a note

User Contributed Notes 1 note

up
0
chuck at manchuck dot com
6 years ago
Please note that the file pointer is reset on each call to get resource

官方地址:https://www.php.net/manual/en/mongogridfsfile.getresource.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3