0
\$\begingroup\$

Zend framework 1. Physically, the file does not exist, it is created based on database.

Okay so use header?

public function downloadAction()
{
    $id = $this->getRequest()->getParam("id");
    $optin = new Application_Model_Optin();
    //$data = $optin->getCodesFromDownload($id);
    $data = array(
        array('code' => 12345),
        array('code' => 12346),
        array('code' => 12347),
        array('code' => 12348),
        array('code' => 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;
}
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Yes. It is perfectly acceptable.

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

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.