I am trying to download ai/png from mysql DB but all I get is an empty file. On the table I only have id and two longblob (file_ai, file_png). For example, file adobe illustrator view is:
echo CHtml::link('<span class="glyphicon glyphicon glyphicon-download-alt" aria-hidden="true"></span>',
array('User/downloadFile', 'id' => $file->id, 'ext' => 'application/illustrator'),
$htmlOptions = array('class' => 'toolMes', 'download', 'data-toggle' => 'tooltip', 'data-placement' => 'bottom', 'title' => 'Download Ai'));
In the controller:
public function actionDownloadFile($id, $ext) {
$file = Files::model()->findByPk($id);
if ($ext === 'application/illustrator') {
header("Content-length:" . strlen($file->file_ai));
header("Content-type: " . $ext . "");
header('Content-Disposition: attachment; filename="' . $file->id . '_' . date("Y-m-d") . '.ai"');
} else {
header("Content-length:" . strlen($file->file_png));
header("Content-type: image/png");
header('Content-Disposition: attachment; filename="' . $file->id . '_' . date("Y-m-d") . '"');
}
}
Hope it is enough to have your precious suggestions