在 zend 框架中显示存储在 public 文件夹之外的图像
我将照片文件夹存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用它,但某些旧版本的 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
为什么要尝试将标题设置为 image/jpeg 类型?
你能不能只设置
$this->view->logo = /path/to/jpeg
然后在你的视图脚本中
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