Ashwin
Ashwin

Reputation: 455

download files using Yii2 gridFS

I want to download files from gridfs using YII2. I am new to Yii I have used this code

   class classname extends \path\controller{   
   $connection = new \yii\mongodb\Connection([
        'dsn' => 'mongodb://localhost:27017/files',
    ]);
    $connection->open();
    $fileCollection = new Collection();
    $collection = $connection->getCollection('fs.files');
    $records = $collection->findOne(["_id"=>'548171105e24cfe00c0000ee'],["filename"]);

but I have retrived the file details. can anyone please tell me how to proceed further for downloading a file.

Upvotes: 0

Views: 587

Answers (1)

ruslantum
ruslantum

Reputation: 1

You can use the fileSend() method

http://www.yiiframework.com/doc-2.0/yii-web-response.html#sendFile()-detail

Upvotes: 0

Related Questions