ragua
(Brice)
November 28, 2012, 10:18am
1
Hi,
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));
unlink($dir.'/'.$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?
konapaz
(Konapaz)
November 28, 2012, 11:10am
2
You can redirect to a controller/action to downloads the file
See an example on
php, jquery, ajax, yii
ragua
(Brice)
November 28, 2012, 1:18pm
3
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:
<?php
echo CHtml::ajaxLink("Pour exporter les données, cliquez sur ce lien",
$this->createUrl('exportEtudiants'),
array(
"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?
konapaz
(Konapaz)
November 29, 2012, 8:46am
5
ragua:
… 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
ragua
(Brice)
November 29, 2012, 1:54pm
6
Thanks KonApaz, but i think i am missing something.
I will try again in several days, maybe my brain will be fixed then.
ragua
(Brice)
December 12, 2012, 2:37pm
7
With a little rest i finally understood what you meant, it was in fact very clear. And it works!
Thanks a lot KonApaz!
KonApaz:
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