如何让 Yii sendFile 函数将 Content

编程入门 行业动态 更新时间:2024-10-13 20:20:14
本文介绍了如何让 Yii sendFile 函数将 Content-Desposition 设置为内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 Yii::app()->request->sendFile() 在视图中显示图像而不弹出下载对话框",但我是无法这样做,因为 sendFile 正在将 Content-Desposition 设置为 attachment.如何将其设置为 inline ?

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 ?

顺便说一句,我使用过 xsendfile 函数,但由于您需要在 Apache 中使用 mod-xsendfile 来使用它,因此放弃了它.

BTW I have used xsendfile function, but ditched it as you need mod-xsendfile in Apache to use it.

请帮忙.

推荐答案

如果要在视图中显示图像,则需要使用 标签.

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();

这也是 sendFile() 原则上所做的,尽管它提供了更多的便利,因为它从文件的扩展名中检测适当的 MIME 类型并发送一堆额外的 HTTP 响应头(包括不受欢迎的 Content-Disposition 一).你可以看看为自己.

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.

这篇关于如何让 Yii sendFile 函数将 Content-Desposition 设置为内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:38:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   Yii   sendFile   Content

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!