Answer the question
In order to leave comments, you need to log in
Rendering images and videos from mongodb with the power of php?
Good afternoon, dear experts!
The crux of the matter is as follows.
There is a task to display data (text, pictures, video) from the database using php.
I am a complete zero php, so the question is:
<?php
// Config
$dbhost = 'localhost';
$dbname = 'test';
// Connect to test database
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
// select the collection
$collection = $db->Boroda;
// pull a cursor query
$cursor = $collection->find();
echo $cursor->count() . ' document(s) found. <br/>';
foreach ($cursor as $obj) {
echo $obj['Text0'] . '<br/>';
$count++;
}
$gridFS = $db -> getGridFS();
// Получаем файл по id
$file = $gridFS -> findOne(array('_id' => new MongoId('5706388608baf803e414368d')));
// посылаем пользователю бинарное представление файла
echo $file -> getBytes();
?>
Answer the question
In order to leave comments, you need to log in
Why would you store files in a DB? Keep links to files!
You need to specify the correct content-type in the header,
If you need something in the browser to pop up a save file dialog, then you need to specify the content-disposition
> Binary, only files.
Add a header indicating what you are giving away and that's it.
Insert into the page for example
But this is of course a so-so option.
It is better to make some kind of cache for such a thing, and cache on nginx, for example, what was given.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question