public function actionFakeApi2($id)
{
Yii::$app->response->headers->set('Content-Type', 'image/png');
return file_get_contents(Yii::getAlias("@webroot/images/{$id}.png"));
}
Does not display an image (Content-Type: text/html)
But
public function actionFakeApi2($id)
{
Yii::$app->response->headers->set('Content-Type', 'image/png');
Yii::$app->response->send();
echo file_get_contents(Yii::getAlias("@webroot/images/{$id}.png"));
}
Does?
Shouldn’t both behave the same? Is there a reason why the logic is separated and the headers aren’t applied on a return?
It is worth noting that in the second case if I replace "echo" with "return" it does not work either.
Thanks!! I never checked the API on this one, only the guide documentation that does not mention the RAW format. I will make a pull request with the addition to the documentation