Mongo has installed, works with collections and documents, I look through everything I have through robomongo.

But the task appeared to save files in the database. I found a bunch of ready-made examples, I've already tried everything,

Writes that he does not know what is GetGridFS ()

$ m = new MongoDB \ Client ("adressserver ...."); $ db = $ m-> selectDB ("local");

// Get the users collection // $ c_faq = $ db-> faq;

// GridFS. Here says that there is no such method! $ grid = $ db-> getGridFS ();

// The file's location in the File System $ filename = "imagen1.png";

// Note metadata field & filename field $ storedfile = grid-> storeFile ($ path. $ Filename, array ("metadata" => array ("filename" => $ filename), "filename" => $ filename)) ;

// Return newly stored file's Document ID echo $ storedfile;

  • Can you attach the error itself that PHP gives you? - Zhukov Roman
  • Yes, easily) prntscr.com/bz2zrx Only it looks like @ Minor is right, apparently we saw gridFS from a new module .... what to do xs - Alex Lizenberg

1 answer 1

With access to monge from PHP is now a frank mess. There is a mongo extension and there is a mongodb extension. One deprecated and in PHP 7 is already missing, another supposedly alive, functional from the word in any way and requiring some kind of wrapper to work.

Here in this mess and you are in a heap. MongoDB\Client is just a wrapper over the new mongodb extension. From the documentation:

Support for GridFS is forthcoming.

Those. GridFS it does not know how at all now. Still, almost a year from the release of PHP 7, where the old mongo is no longer working.

And getGridFS is from the old mongo extension. And GridFS can do it, but PHP 7 doesn’t. Why should the developers of these modules do this and immediately drop the support of a more functional module without providing a replacement for the functional — I don’t know. Perhaps, in PHP 7, the necessary interfaces for extensions have changed dramatically and there were no people willing to adapt the old code.

What to do with it:

  • google other wrappers over the mongodb extension, which nevertheless mastered gridfs - google is nontrivial because of a jumble of identical names, I just tried to get links to the old extension;
  • write your own patch that implements the GridFS and shove it into the mongo-php-library . You will be many who are grateful;
  • sit on PHP 5.6 and mongo (fortunately, mongo and mongodb do not at least conflict with each other and can work simultaneously). PHP 5.6 LTS, security fixes will receive two more years;
  • do some customized workarounds.
  • Thank! I thought so, it is not pure here. But the question is that I have the following php 5.5.9 config and I installed everything according to the instructions from the php site. The mongodb.so module appeared. And is it easier, as it were, to install the old extension, where can I get it? I just don't know how to write this patch, I can hardly manage it - Alex Lizenberg
  • Can it really be easier to get an old extension? Throw it in php / lib and connect? I’m already tired of going to the forums for a week and don’t understand what it doesn’t work for me ... I would gladly have developed a patch, if I knew how it is - Alex Lizenberg
  • Ltd! I can put on this instruction the old extension ?? php.net/manual/en/mongo.installation.php right now I will try - Alex Lizenberg
  • Yes, the old mongo extension is set up like any other PECL extension. Simultaneously with mongodb get along normally, checked. - Small
  • Thanks again, it all worked on the old module. Tell me, I work with the file, save the file like this Save additional fields $ storedfile = $ grid-> storeFile ($ path. $ Filename, array ("filename" => $ filename, "fileSize" => filesize ($ path. $ filename), "mineType" => $ mineType)); How to get these fields ??? That's how I get the file $ image = $ gridFS-> findOne ($ filename); And how to get additional meta data - Alex Lizenberg