Sendfile Issue


i am trying to download a file that i just created.

Here is the end of my controller action:


$dir = Yii::getPathOfAlias('application.uploads');

$name = $synthese->group_description . '.csv';

$name = str_replace('è', 'e', $name);

$filename = $dir. '/' . $name;

$content = $csv->toCSV($filename, ",", "\""); 

return Yii::app()->getRequest()->sendFile($name, @file_get_contents($filename));


The sendFile function is supposed to open a dialog box to ask me where i want to stire the file, but it didn’t appear.

I am sure of the name of the file and it contents (checked with var_dump), i also var_dump in the CHttpRequest.php file, i just can’t figure what ther problem is.

Did someone got an idea?

You can redirect to a controller/action to downloads the file

See an example on

Thanks you for your reply KonApaz, but i don’t really see what i have to change in my code.

I tried to specifiy the location in the ajaxlink i use to call my function in the admin form:


echo CHtml::ajaxLink("Pour exporter les données, cliquez sur ce lien",



"type" => "post",   

'javascript:window.location.assign( Yii::getPathOfAlias("application.uploads") );',

"data" => "js:{ids:$.fn.yiiGridView.getSelection('group-synthese-grid')}",



but no effect.

Have you got a complete example in yii?

… anyone? …

There are 2 ways you can do it,

One is the redirect on request and the other by javascript after of the first request is completed

if you choose the javascript-ajax, check with firebug the requests, also check the javascript firebug console and see if your javascript redirect called or any error exists

Thanks KonApaz, but i think i am missing something.

I will try again in several days, maybe my brain will be fixed then.

With a little rest i finally understood what you meant, it was in fact very clear. And it works!

Thanks a lot KonApaz!