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;
}
Heslacher
50.9k5 gold badges83 silver badges177 bronze badges
asked Aug 21, 2015 at 14:28
\$\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.

answered Aug 24, 2015 at 5:26
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.