View Pdf

I have placed a PDF file in folder /protected/uploads. I want to view this file on click of hyperlink. But i am facing the error and the PDF is not being displayed.


Error 404

Unable to resolve the request "uploads/viewPdf".

Here is what i have done to view the file.





                'uploads/<filename:[a-zA-Z]+\.pdf>' => 'Upload/viewPdf',







class UploadController extends Controller


	public function actionIndex()




    public function actionViewPdf()


        $filename = $_GET['filename'] . '.pdf';

        $filepath = '/uploads/Tutorial.pdf' . $filename;



            // Set up PDF headers

            header('Content-type: application/pdf');

            header('Content-Disposition: inline; filename="' . $filename . '"');

            header('Content-Transfer-Encoding: binary');

            header('Content-Length: ' . filesize($filepath));

            header('Accept-Ranges: bytes');

            // Render the file





            // PDF doesn't exist so throw an error or something




and the link in the form. I would like to mention here is that the form belong to other controller not the upload controller


echo CHtml::link(


        Yii::app()->createUrl('/uploads/viewPdf', array('filename' => 'Tutorial')) ,

        array('class'=>'btnPrint btn btn-danger','target'=>'_blank'));

Why don’t you save public files in a folder at same level of protected folder?

So your files will be accessed without restrictions.


Yii::app()->createUrl('/upload/viewPdf', array('filename' => 'Tutorial')) ,

(no plural, just as your controller name)

No its not working.