Opening image in a new tab

Good morning everyone,

i have the following problem,

I have saved some images in the uploads / upload folder

in the view I have a link

echo Html :: a ($ upload, ['download-file', 'nameFile' => $ upload, 'id' => $ message-> thread], ['class' => '', 'target' => '_blank'])

which calls an action which returns the image

public function actionDownloadFile ($ nameFile, $ id = null)
{
....
....
     return Yii :: $ app-> response-> sendFile ($ target, $ nameFile);

everything works fine, the problem is that if it is a pdf file, it is correctly opened in a new tab

if instead it is a jpg image, the download starts automatically, but, similar to the pdf, I would like the image to be shown in a new tab

what am I doing wrong?

thank you

Because you are downloading. Display an image instead

1 Like

Thanks for the reply, I tried the inline => true parameter and it works

return Yii::$app->response->sendFile($target, $nameFile, [‘inline’ => true]);

1 Like