Difference between #8 and #10 of
Upload files in Yii2 with MongoDb and GridFs

Revision #10 has been created by skworden on Oct 30, 2014, 11:15:55 PM with the memo:

forgot to update one line
« previous (#8) next (#11) »

Changes

Title unchanged

Upload files in Yii2 with MongoDb and GridFs

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

yii2, mongodb, gridfs, File upload

Content changed

[...]
#### 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).
[...]
6 0
6 followers
Viewed: 36 059 times
Version: 2.0
Category: How-tos
Written by: edoardo849
Last updated by: pceuropa
Created on: Feb 9, 2014
Last updated: 4 years ago
Update Article

Revisions

View all history