略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoGridFSFile::write

2024-05-15

MongoGridFSFile::write

(PECL mongo >=0.9.0)

MongoGridFSFile::writeWrites this file to the filesystem

说明

public MongoGridFSFile::write ([ string $filename = NULL ] ) : int

参数

filename

The location to which to write the file. If none is given, the stored filename will be used.

返回值

Returns the number of bytes written.

范例

Example #1 MongoGridFSFile::write() example

<?php

$images 
$db->my_db->getGridFS('images');

$image $images->findOne('jwage.png');
$image->write('/path/to/write/jwage.png');
?>
add a note add a note

User Contributed Notes 1 note

up
0
dimzon541 at gmail dot com
3 years ago
write method produce a huge memory leak!
workaround: use getResource

==============8<===========================

$chunkSize = intval($f->file['chunkSize']);
//echo $chunkSize;
$stream = $f->getResource();
$outStream = fopen($tmp,'wb');
while (!feof($stream)) {
   fwrite($outStream, fread($stream, $chunkSize));
}
fclose($stream);
fclose($outStream);
unset($stream);
unset($outStream);

==============8<===========================

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

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