【问题标题】:Display images stored outside the public folder in zend framework在zend框架中显示存储在公用文件夹之外的图像
【发布时间】:2011-11-01 13:58:48
【问题描述】:

我的照片文件夹存储在 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;

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

希望有人能帮忙 - 谢谢

【问题讨论】:

    标签: php zend-framework profile photo


    【解决方案1】:

    你可以使用这个,但是在一些旧版本的 IE 上会出现问题

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

    【讨论】:

      【解决方案2】:

      您为什么要将标题设置为 image/jpeg 类型?

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

      然后在你的视图脚本中

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

      【讨论】:

      • 他说的是一个非公开目录,所以他正在尝试读取它然后输出数据。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2020-12-19
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多