Behavior to save Files


(Shalanga) #1

This behavior automate the tedius procedure to save the file in to the disk.


public function behaviors()

{

        return array('saveFileBehavior' => array('class' => 'SaveFileBehavior',

                                                 'campo' => 'myTableField', // field in table which stores the file name

                                                                           )

                   );

}


<div class="simple">

	<?php echo CHtml::activeLabelEx($model, 'myTableField'); ?>

	<?php echo CHtml::activeFileField($model, 'myTableField', array('size' => 40)); ?>

</div>




What does this Behavior?

It saves the file automactly here:

/protected/<someFolder>/<primary_key>/<table_attribute_name>

It’s very simple and it works.

You may customize it, i don’t know if it’ll work for everyone.

Attachments are in the post, just download them here: http://www.yiiframework.com/forum/index.php?/topic/3814-behavior-pra-salvar-arquivos-de-upload/#entry20451