I am trying to use Yii::app()->request->sendFile()
to display images in the view without the 'Download Dialog box' popping up, but I am unable to do so as sendFile is setting Content-Desposition
to attachment
. How do I make it set it to inline
?
BTW I have used xsendfile function, but ditched it as you need mod-xsendfile in Apache to use it.
Please Help.
If you want to display images in the view then you need to use <img>
tags.
If you want the returned content to be an image (in which case it's meaningless to talk about a view) then all you need to do is usually no more than
header('Content-Type: image/jpeg');
echo $binaryImageContents;
Yii::app()->end();
That's also what sendFile()
does in principle, although it offers a bit more convenience because it detects the appropriate MIME type from the file's extension and sends a bunch of additional HTTP response headers (including the undesirable Content-Disposition
one). You can take a look for yourself.