在 zend 框架中显示存储在 public 文件夹之外的图像

发布于 2024-12-01 09:43:04 字数 816 浏览 0 评论 0原文

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

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

希望有人可以帮助 - 谢谢

I have my photo folder stored in the data folder in a Zend Framework application. when i try to read the image files from the data folder to display as a user profile photo in my view i cant get it display and it only show up when i disable my view and layout.

This is my sample code:

$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;

I want to get the profile photos and display it in the user profile page

hope someone can help - thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ杯具 2024-12-08 09:43:04

您可以使用它,但某些旧版本的 IE 有问题

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

you can use this, but has problem with some older versions of IE

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

掩饰不了的爱 2024-12-08 09:43:04

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

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

然后在你的视图脚本中

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

Why are you trying to set a header as type image/jpeg?

Can you not just set $this->view->logo = /path/to/jpeg

Then in your view script

<img src="<?php echo $this->logo; ?>" alt="" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文