Php 使用WideImage显示数据库中的PNG
使用WideImage扩展,我尝试使用以下函数从数据库渲染图像斑点:Php 使用WideImage显示数据库中的PNG,php,mysql,database,yii,wideimage,Php,Mysql,Database,Yii,Wideimage,使用WideImage扩展,我尝试使用以下函数从数据库渲染图像斑点: 受保护的函数renderControlNonEditable() { 断言(“$this->model instanceof Item | |$this->model->getModel()instanceof Item”); $content=null; 如果($this->model->files->count()>0) { $content.='; foreach($this->model->fileas$fileMod
受保护的函数renderControlNonEditable()
{
断言(“$this->model instanceof Item | |$this->model->getModel()instanceof Item”);
$content=null;
如果($this->model->files->count()>0)
{
$content.=';
foreach($this->model->fileas$fileModel)
{
$filecontent=filecontent::getById($fileModel->id);
$filecontent=$filecontent->content;
$content.='- ';
$content.=FileModelDisplayUtil::renderDownloadLinkContentByRelationModelAndFileModel($this->model,
$fileModel);
$content.=''.FileModelDisplayUtil::convertSizeToHumanReadableAndGet((int)$fileModel->size);
$content.='
';
$content.=WideImage::load($filecontent);
}
$content.='
';
}
返回$content;
}
但是当渲染$content
时,它会显示以下BLOB字符串,而不是渲染图像
�PNG IHDRd$��8:IDATh�ݛy|Օ����
如何确保发布了正确的标题?我能做些什么来解决这个问题
public function actionImage($model, $fileModel)
{
$filecontent = FileContent::getById($fileModel->id);
$filecontent = $filecontent->content;
$content = WideImage::load($filecontent);
return $content;
}
正如其他人提到的,您不能在html页面上转储wideimage(或任何图像)的输出。最好的解决方案(我想也是如此)是创建另一个只处理图像的函数
�PNG IHDRd$��8:IDATh�ݛy|Օ����
您应该像现在一样创建html,而不是
$content .= FileModelDisplayUtil::renderDownloadLinkContentByRelationModelAndFileModel($this->model, $fileModel);
我相信这是得到图像内容,有一个
$content .= '<img src="'.$this->createUrl('image',array('file'=>$fileModel)).'">'
$content.='createUrl('image',array('file'=>$fileModel))。“>'
你的函数(actionImage)应该在同一个控制器中(无论如何在我的示例中)应该得到blob,做任何你想做的事情,然后输出图像(只有图像,没有html).我知道这一点,但是如何/在哪里?WideImage扩展应该自动检测并发送标题。你不能只是将图像的原始字节转储到html页面。你需要通过
标记单独加载。@MarcB我该怎么做?我似乎无法获得正确的语法!请帮助!太棒了,这似乎是我需要的用actionImage函数更新了我的问题。我似乎得到了这个URL``。我刚刚掌握了所有这些的窍门,所以任何示例/解释都会很棒。$content=WideImage::load($filecontent);return$content;我不确定这是否是输出的方式。我通常使用WideImage::load('image1.png')->resize(100100)->output('gif'));输出函数创建正确的标题等。是的,我已经看到了很多确切的语法,但我正在从数据库blob加载文件。