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


I have these functions in the controller project.

public function actionCreate()


	$model=new Project;



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



	// Uncomment the following line if AJAX validation is needed

	// $this->performAjaxValidation($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){  


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



  return ($ffile);



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

array(‘attachment’, ‘file’,


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

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


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