Use header application/x-download Zend framework 1. Physically, the file does not exist, it is created based on database.

Okay so use header?

public function downloadAction()
{
    $id = $this-&gt;getRequest()-&gt;getParam("id");
    $optin = new Application_Model_Optin();
    //$data = $optin-&gt;getCodesFromDownload($id);
    $data = array(
        array('code' =&gt; 12345),
        array('code' =&gt; 12346),
        array('code' =&gt; 12347),
        array('code' =&gt; 12348),
        array('code' =&gt; 12349)
    );

    header("Content-type: application/x-download");
    header("Content-disposition: attachment; filename=code_" . $id . ".csv");

    foreach($data as $item)
    {
        echo $item['code']."\r\n";
    }
    die;
}
Yes. It is perfectly acceptable.

This Stack Overflow post demonstrates that the header is simply used for naming the file.