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

  1. Requirements
  2. Installation
  3. Usage
  4. Sample Controller Action
  5. Note
  6. For any Questions or Suggestions feel free to ask me!

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

Requirements

Yii 1.1.14

Installation

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

'import' => array(
        'ext.ruploadbehavior.*'
    ),

Usage

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);

		if(isset($_POST['Product']))
		{
			$model->attributes=$_POST['Product'];
			if($model->save())
                        $this->redirect(array('view','id'=>$model->id));			
		}
		$this->render('create',array(
			'model'=>$model,
		));
	}
		 

Note

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!

0 0
1 follower
161 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Others
Tags:
Developed by: Ahamed Rifaideen
Created on: Apr 11, 2014
Last updated: 10 years ago

Downloads

show all