Difference between #2 and #3 of
How to use YiiBooster TbFileUpload widget

Changes

Title unchanged

How to use YiiBooster TbFileUpload widget

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

YiiBooster, How to, File upload

Content changed

[...]
I normally create a `files` folder and I allocate it within my `www` one, that is where I keep my css, js, images files. So, even though you can place it where ever you wish and for the sake of the example, I will use the `files` folder name.

I also assume that you have configured a path alias that references the `files` folder. On this example, the path alias is `frontend.www.files`.

### Note   
 
* This demo only works if the MyModel class already includes the function getImageUrl($img_type=null). If not, comment the 2 lines inside the data array, where 'url' and 'thumbnail_url' are defined, to make the demo work  
 
* If the MyModel has a different name, it needs to be replaced 1-2 times inside the upload action  
 
* The url where we are going to upload our files => upload action  
 
 
_Thanks [Don Felipe](http://www.yiiframework.com/user/9450/)_  
 
 
### Setup your model
The way you handle validation on the server is up to you, the configuration I am going to provide now is just an example.
[...]
$model = new MyModel('upload');
$model->picture = CUploadedFile::getInstance($model, 'picture');
if ($model->picture !== null && $model->validate(array('picture'))
)
{
$model->picture->saveAs(
[...]
Final Notes
------------------
The upload action example was not really tested, if any of you had problems with it, please submit your changes to the [YiiBooster Forum Topic](http://www.yiiframework.com/forum/index.php/topic/36258-yiibooster/). Any help would be highly appreciated to improve this wiki.

 
 
7 0
19 followers
Viewed: 54 325 times
Version: 1.1
Category: How-tos
Written by: Antonio Ramirez
Last updated by: Antonio Ramirez
Created on: Dec 9, 2012
Last updated: 11 years ago
Update Article

Revisions

View all history