Uploading Multiple Files(Doc, Pdf...) And Viewing Them

Hi,

I have these functions in the controller project.

public function actionCreate()

{


	$model=new Project;





	 if($filez=$this->uploadMultifile($model,'attachment','/uploads/doc/'))


     {


        $model->attachment=implode(",", $filez);


     }


	


	// Uncomment the following line if AJAX validation is needed


	// $this->performAjaxValidation($model);





	if(isset($_POST['Project']))


	{


		$model->attributes=$_POST['Project'];


		if($model->save())


			$this->redirect(array('view','id'=>$model->proj_id));


	}





	$this->render('create',array(


		'model'=>$model,


	));


}








//Upload multiple files action


public function uploadMultifile ($model,$attr,$path)


{


/** path when uploads folder is on site root.


  * $path='/uploads/doc/'


  */





    if($sfile=CUploadedFile::getInstances($model, $attr))


	{


      foreach ($sfile as $i=>$file){  


      $formatName=time().$i.'.'.$file->getExtensionName();


      $file->saveAs(Yii::app()->basePath .DIRECTORY_SEPARATOR.'..'. $path.$formatName);


      $ffile[$i]=$formatName;


    }


  return ($ffile);

}

}

[sub][sub]Model rule i have:[/sub][/sub]

array(‘attachment’, ‘file’,

		'types'=>'docs,docx.pdf,txt',


	    'maxSize'=>1024 * 1024 * 1,//1MB


		'tooLarge'=>'The was larger than 1MB. Please upload a smaller file.',


		'allowEmpty'=>1,),

[sub][sub]And this is my _view file:[/sub][/sub]

<b><?php echo CHtml::encode($data->getAttributeLabel('attachment')); ?>:</b>


<?php echo CHtml::encode($data->attachment); ?>


<br />

Quite alright am able to upload the documents successfully but when viewing the attachments are just showing the filename and extension.

How can i view the uploaded docs so that i can even download them?

Have a look at Yii’s sendFile.


Yii::app()->request->sendFile("FilenameToBeDisplayed", file_get_contents($pathToFile));

Matt