lundi 28 novembre 2016

Yii2: how to change/add response headers?

I have some truble with Yii2. I try to add/set response headers in my controller's action. Below is code:

   Yii::$app->response->headers->set('Content-type', ['application/pdf']);
   Yii::$app->response->headers->set('Content-Disposition', ['inline', 'filename=' . $fileName]);
   Yii::$app->response->headers->set('Content-Transfer-Encoding', ['binary']);
   Yii::$app->response->headers->set('Content-Length', [$fileSize]);
   Yii::$app->response->headers->set('Accept-Ranges', ['bytes']);

   return readfile($filePath);

If I change set() to add(), or second argument from array to string so get no reaction. Pdf file is not opened. But if I use native PHP header() method - all works correct.




Aucun commentaire:

Enregistrer un commentaire