MongoGridFSFile::write
(PECL mongo >=0.9.0)
MongoGridFSFile::write — Writes this file to the filesystem
Description
public int MongoGridFSFile::write
([ string
$filename
= NULL
] )Parameters
-
filename
-
The location to which to write the file. If none is given, the stored filename will be used.
Return Values
Returns the number of bytes written.
Examples
Example #1 MongoGridFSFile::write() example
<?php
$images = $db->my_db->getGridFS('images');
$image = $images->findOne('jwage.png');
$image->write('/path/to/write/jwage.png');
?>
- 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
Коментарии
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<===========================