the same work can be done by follow code:
header(\'Content-Type:image/jpeg\');
readfile(\'a.jpg\');
but now I really confused by Yii2\'s
Yii2 already has built-in function for sending files. This way you do not need to set response format and content type will be detected automatically (you can override it if you wish):
function actionDownload()
{
$imgFullPath = 'picture.jpg';
return Yii::$app->response->sendFile($imgFullPath);
}
..
If the file is only temporary created for current download action you can use AFTER_SEND
event to delete the file:
function actionDownload()
{
$imgFullPath = 'picture.jpg';
return Yii::$app->response
->sendFile($imgFullPath)
->on(\yii\web\Response::EVENT_AFTER_SEND, function($event) {
unlink($event->data);
}, $imgFullPath);
}