在zend框架中显示存储在公用文件夹外部的图像

时间:2011-08-23 00:46:24

标签: php zend-framework profile photo

我的照片文件夹存储在Zend Framework应用程序的数据文件夹中。当我尝试从数据文件夹中读取图像文件以在我的视图中显示为用户个人资料照片时我无法显示它并且只有在我禁用我的视图和布局时才显示。

这是我的示例代码:

$appShortPath = $photPlugin->getPathToFileFolders();

$databaseFile = '2011/08/18/17c7025cd9f3436e4ad1c02635cc6754.jpg';           

$appPath = $appShortPath . '/data/UploadPhotos/';

if(!isset($databaseFile))
{
  return false;
}

$fullPath = $appPath . $databaseFile;

if(!file_exists($fullPath))
{
  return false;
}

$this->_helper->viewRenderer->setNoRender(true);
$this->view->layout()->disableLayout();

$image = readfile($fullPath);

header('Content-Type: image/jpeg');

$this->getResponse()
  ->setHeader('Content-Type', 'image/jpeg');   

$this->view->logo = $image;

我想获取个人资料照片并将其显示在用户个人资料页面

希望有人可以提供帮助 - 谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用此功能,但某些旧版本的IE

存在问题

http://en.wikipedia.org/wiki/Data_URI_scheme

答案 1 :(得分:-2)

为什么要尝试将标题设置为type / jpeg?

你能不能只设置$this->view->logo = /path/to/jpeg

然后在您的视图脚本中

<img src="<?php echo $this->logo; ?>" alt="" />
相关问题