Yii v2 snippet guide II

Comparing #50 with #51

Revision #51 was created by rackycz rackycz on Oct 11, 2020, 5:35:57 PM.

base64 stream download

Content

[...]
Yii::$app->response->headers->set('Content-Type', 'application/pdf');

// This row will download the file. If you do not use the line, the file will be displayed in the browser.
// Details here:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#Downloads
//
 Yii::$app->response->headers->set('Content-Disposition','attachment; filename="hello.pdf"');

// Here is used the temporary stream
Yii::$app->response->stream = $stream;

// You can call following line, but you don't have to. Method send() is called automatically when current action ends:
[...]