Veamos como subir ficheros en Yii framework.
El controlador:
public function actionIndex(){
$form=new UsuariosForm();
if(isset($_FILES["UsuariosForm"])){
//Instanciamos el subidor para el campo fichero del formulario
$file=CUploadedFile::getInstance($form,"fichero");
//Nombre del fichero
$name=time()."-".$file->getName();
//$file->getExtensionName()
//Permitimos tres tipos de fichero
if($file->getExtensionName()=="png" || $file->getExtensionName()=="pdf" || $file->getExtensionName()=="zip"){
//Guardamos el fichero
$file->saveAs(Yii::getPathOfAlias("webroot")."/uploads/".$name);
}else{
//Crear mensaje flash
Yii::app()->user->setFlash('mensaje','Solo ficheros png, pdf o zip');
//Refrescamos pantalla
$this->refresh();
}
}
$this->render('index',array(
"form"=>$form
));
}
La vista:
<h1>Subir ficheros con Yii</h1>
<?php echo CHtml::beginForm('','post',array("name"=>"form","id"=>"form","enctype"=>"multipart/form-data"));?>
Fichero ( Png, pdf o zip )
<?php
echo CHtml::activeFileField($form,"fichero");
?>
<br/>
<?php echo CHtml::submitButton('submit',array("class"=>"btn btn-success","value"=>"Subir","title"=>"Subir")); ?>
<?php if(Yii::app()->user->hasFlash('mensaje')){
//Mostrar mensaje flash
?>
<span class="alert alert-danger"><?php echo Yii::app()->user->getFlash('mensaje')?></span>
<?php } ?>
<?php echo CHtml::endForm();?>
El mensaje de error flash solo se muestra una vez.

Más información:
http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/
http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/













