<?php

$downloadFileName = "phonalisa-file_$name" . "_" . date('Y-m-d_H-i-s') . ".wav";
$downloadFileName = str_replace(" ", "-", $downloadFileName);

if ($data) {

    header("Content-disposition: attachment; filename=$downloadFileName");
    header("Pragma: no-cache");
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Transfer-Encoding: binary ");
    header('Content-type: ' . $type);

    print $data;
} else {
    throw new CHttpException(404, 'not found');
}
