aruna470
(Aruna470)
February 19, 2012, 12:33am
1
Hi,
In my application I want to download ".wav" files. To do that I have written a common method in common class and call it.Below is that function.Problem is when I clicked download file get downloaded but it is corrupted, not played in any of players.There is no issue with the original file in sever.I tried this writing a separate php script without using the framework and worked fine.What can be the issue.
public function downloadContentEx($contentPath, $fileName)
{
$fileName = $fileName . Yii::app()->params['promptExtension'];
$cont_file = $contentPath . '/' . $fileName;
if (is_file($cont_file))
{
$file_type = mime_content_type($cont_file);
$content = file_get_contents($cont_file);
Yii::app()->getRequest()->sendFile($fileName, $content, $file_type, false);
exit();
}
else
{
return false;
}
}
Thanks
Aruna
twisted1919
(Serban Cristian)
February 19, 2012, 12:48am
2
I had same issue with large files, dunno really why but i did it in the "traditional" way after all.
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
aruna470
(Aruna470)
February 19, 2012, 1:08am
3
twisted1919:
I had same issue with large files, dunno really why but i did it in the "traditional" way after all.
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
Thanks for sharing, this worked fine. Spent whole day for fixing it