Answer the question
In order to leave comments, you need to log in
Php, unable to save file to mongoDB. Where to get classes?
So I found this code on the Internet
<?php
require 'vendor/autoload.php';
$mongo = new MongoClient("mongodb://localhost:27017"); // Mongo // MongoDB\Client
$db = $mongo->myfiles;
// GridFS
$grid = $db->getGridFS();
// The file's location in the File System
$path = "./";
$filename = "imany_never.mp3";
// 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 . PHP_EOL;
Answer the question
In order to leave comments, you need to log in
I figured out that you need to use the old module for php, not mongodb, namely mongo
It has support for gridFS and the new one has not yet implemented
the installation php.net/manual/en/mongo.installation.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question