Difference between #4 and #11 of
Saving files to a blob field in the database

Changes

Title unchanged

Saving files to a blob field in the database

Category unchanged

Tips

Yii version unchanged

Tags unchanged

File upload

Content changed

[...]
### Edit the view:

In the view we can put:


 
 

```php
<div class="row">
[...]
### Displaying images:

In the view we put the code:
 
 
 
```php 
<? echo CHtml::link(my_link_name,array('displaySavedImage','id'=>$model->primaryKey)); ?>
 
```
 
 
So it generates link like http://myserver/yii/myapp/index.php?r=candidate/displaySavedImage&id=1
 
 
Where Candidate is current model.
 
 
To show thesaved image we can write an action:
 
 
 in Controller: ```php /** * Displays the preview of the photoOpens the dialog in browser to open/save the image. */ public function actionDisplaySavedImage() { $model=$this->loadModel();
 
header('Content-Type: '.$model->file_type);
 
echo $model->file_content;
 
}
 
```
$_GET['id']);
 
 
header('Pragma: public');
 
header('Expires: 0');
 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 
header('Content-Transfer-Encoding: binary');
 
header('Content-length: '.$model->file_size);
 
header('Content-Type: '.$model->file_type);
 
header('Content-Disposition: attachment; filename='.$model->file_name);
 
 
        echo $model->file_content;
 
}
 
```
 
 
Note *$_GET\['id'\]* as passed argument of loadModel function.
6 2
17 followers
Viewed: 80 819 times
Version: 1.1
Category: Tips
Written by: zaccaria
Last updated by: zaccaria
Created on: Nov 3, 2010
Last updated: 14 years ago
Update Article

Revisions

View all history