Xml File Download

Hi all, I would like to add download link for downloading xml file from my application. Here is the code i tried in my local and it not working.

In view


<?php echo CHtml::link('Download file',array('ProgramDetail/Download','id'=>$id)); ?>

In controller


 public function actionDownload($id)

        {

            echo $id;

            $res2= ProgramDetail::model()->findByAttributes(array('program_id'=>$id));

            $file= $res2->program_form_name;

            $filecontent=file_get_contents(Yii::app()->baseUrl.'/images/form/'.$file);

            header("Content-Type: application/xml");

            header("Content-disposition: attachment; filename=$file");

            

            echo $filecontent;

            exit;

        }

It shows file_get_contents(/application/images/form/1738-test.xml): failed to open stream: No such file or directory

Where is the error?

I suspect you should be using something like this:




$filecontent=file_get_contents(Yii::getPathOfAlias('webroot.images.form') . '/' . $file);