简体   繁体   English

在Yii中如何将图像显示为路径存储在数据库中的输出

[英]In Yii how to display image as output whose path is stored in database

I am creating a project in Yii. 我正在Yii创建一个项目。 I am having table as Dnymedia with fields as, 我有Dnymedia表,字段为

Dnymedia Dnymedia

-mediaId -mediaId

-mediaPath -mediaPath

-contentTitleId -contentTitleId

Suppose I have media path stored as=" F:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures " 假设我的媒体路径存储为=“ F:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures

How do I display this image as output? 如何显示此图像作为输出? I don't need to display it in view. 我不需要在视图中显示它。 I just want to display the image as output of the controller's action in Yii. 我只想在Yii中将图像显示为控制器动作的输出。

instead of read file use file_get_contents 代替读取文件,使用file_get_contents

header('Content-Type: image/jpeg');
echo file_get_contents('F:\Documents and Settings\All Users\Documents\My Pictures\Sample.jpg');
die;
This worked for me.Please check it.

public function actionTest()
    {
        header('Content-Type: image/jpeg');
        readfile('http://localhost/myAppetite/images/bodyBg.jpg');
         die;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM