So I figured out how to store files in the Mongo database

<? $mongo = new MongoClient("mongodb://localhost:27017"); $db = $mongo->selectDB('myfiles'); $grid = $db->getGridFS(); $filename = "imany_never.mp3"; $filename = "video.mp4"; $mineType = "video/mp4"; // Сохраняю файл в базу с доп параметрами! $storedfile = $grid->storeFile($filename, array("filename" => $filename, "fileSize" => filesize($path . $filename), "mineType" => $mineType)); 

I take it out

 <? $image = $gridFS->findOne($filename); echo $image->get('mineType'). PHP_EOL; // Тут пытаюсь получить МИМЕтип файла echo $image->fileSize. PHP_EOL; // так тоже не получается... 

When saving, I give him additional meta data such as type, size, mime, then I will also make a category, tags This is how to get all this when reading ???????

    1 answer 1

    First you need this <? replace with <?php this. Secondly, do so var_dump($image->toArray() find where everything is written there that you want and writes it down and get it out using the get() method

    • DAK I did so) Here is the string echo $ image-> get ('mineType'). PHP_EOL; // error comes out! - Alex Lizenberg
    • Here is an example prntscr.com/c1hzkp PHP error Fatal error: Call to undefined method MongoGridFSFile :: get () in readfile.php on line 36 - Alex Lizenberg
    • @ AlexLizenberg as well as `-> mineType '? - Naumov
    • Well, emae)) in the question, everything is written, and I tried it this way and that! Undefined property: MongoGridFSFile :: $ mineType Look at prntscr.com/c1mkrv these are what methods are there in general and the printout of the object itself - this data is there .... I can't figure out how to get them - Alex Lizenberg
    • var_dump($image) that displays completely? - Naumov