Upload files in Yii2 with MongoDb and GridFs

Comparing #8 with #10

Revision #10 was created by skworden skworden on Oct 30, 2014, 11:15:55 PM.

forgot to update one line

Content

[...]
#### Action Create

Now, the interesting part:

```php
use yii\web\UploadedFile;
 
 
public function actionCreate()
{
$model = new Asset;
[...]
```php
use yii\helpers\Html;
 
use yii\helpers\Url;
 
 
<?= Html::img(Html::urlUrl::to(['asset/get', 'id'=>(string)$model->_id]), ['alt'=>$model->description]);?>

```
[...]
```php
use yii\helpers\Html;
 
use yii\helpers\Url;
 
 
<?php if(strpos($model->contentType,'image')===false): //Not an image?> <iframe src="<?=Html::urlUrl::to(['asset/get', 'id'=>(string)$model->_id]);?>" width="100%" height="600px"></iframe> <?php else: ?> <?= Html::img(Html::urlUrl::to(['asset/get', 'id'=>(string)$model->_id]), ['alt'=>$model->description]);?>
<?php endif; ?>
```

Quick note: this method is **recommended** for all of you guys who have to store sensible user data files (like card IDs, passports and so on) because you can leverage the standard **AccessControl** rules to display a single file so that you can put granular permissions to CRUD operations regarding files too (especially to read operations). If you are thinking of storing your user files in the server and you are not sure of how an .htaccess or apache2.conf file works, then I recommend this method (search engines crawlers can be very nasty when you publish /your/folder/image.png and you forget to remove the "List" permissions).
[...]