PHP Velho Oeste 2024

MongoGridFSFile::write

(PECL mongo >=0.9.0)

MongoGridFSFile::writeこのファイルをファイルシステムに書き込む

説明

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

パラメータ

filename

ファイルの書き込み先。指定しなかった場合は、 格納されているファイル名を使用します。

返り値

書き込んだバイト数を返します。

例1 MongoGridFSFile::write() の例

<?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
8 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<===========================
To Top