K
K
Konstantin2016-07-29 00:46:12
PHP
Konstantin, 2016-07-29 00:46:12

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;

But always swears at the class!
if I leave mongo, then they swear, what kind of mongo? they say the class mongo not found
If I put MongoClient, then they swear what kind of getGridFS
How to work with this GridFS
It works with the base itself if I leave MongoClient
But I need exactly the files

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin, 2016-07-30
@armenka29

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 question

Ask a Question

731 491 924 answers to any question