1. Go to this page and download the library: Download helmich/gridfs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
helmich / gridfs example snippets
$manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
$database = new \MongoDB\Database($manager, 'yourdatabase');
$bucketOptions = (new \Helmich\GridFS\Options\BucketOptions)
->withBucketName('yourbucket');
$bucket = new \Helmich\GridFS\Bucket($database, $bucketOptions);
$uploadOptions = (new \Helmich\GridFS\Options\UploadOptions)
->withChunkSizeBytes(4 << 10)
->withMetadata(['foo' => 'bar']);
$uploadStream = $bucket->openUploadStream("helloworld.txt", $uploadOptions);
$uploadStream->write("Hello World!");
$uploadStream->close();
echo "File ID is: " . $uploadStream->fileId();
$options = (new \Helmich\GridFS\Options\DownloadByNameOptions)
->withRevision(-1); // also the default; will download the latest revision of the file
$stream = $bucket->openDownloadStreamByName('yourfile.txt', $options);