ruploadbehavior manages file upload operations smoothly without writing single line of code
1 follower

ruploadbehavior helps the developer to manage file upload operation and other related file operations such as uploading files with unique name, delete previous file when when new file is uploaded, delete file together with parent record automatically


Yii 1.1.14


place this extension under protected/extensions folder and import it to configuration's import array like this

'import' => array(


attach the behavior provided with this extension into your model as

public function behaviors() 
             return array(
                 'upload' => array(
                     'class' => 'UploadBehavior',
                      //file column name
                     'field' => 'file',
                      // file upload path, path must not end with slash ( / )
                     'path' => 'assets',
                     // upload unique files
                     'renameIfExists' => true,
                      // delete previous file when new file uploaded
                     'delete_previous_file' => true,
              // delete file when parent record is deleted
                     'delete_together' => true

Sample Controller Action

You can use Gii generated actions without any modifications

public function actionCreate()
        $model=new Product;
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);


don't forget to use file field for file upload and the form must use enctype multipart/form-data

For any Questions or Suggestions feel free to ask me!

Be the first person to leave a comment

Please to leave your comment.

Create extension