如何查看Web根目录以外的图像? [英] How to view an image outside of web root?

查看:471
本文介绍了如何查看Web根目录以外的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我要嵌入特定页面上的.png。这是巴纽Web根目录以外的,但我们在我们的系统中的模块,允许用户查看一个单独的页面上的形象。我发现我可以使用iframe来查看一些浏览器的巴纽,但有时一个授权问题或要打印的页面时图像不通过iframe中加载。我试着PHP的ReadFile的(),但我只是另一个授权问题。我找了授权问题奇怪,因为人们必须先登录才能在所有使用我们的网站。什么是嵌入到这个形象的最佳方式是什么?

 &LT; PHP的foreach($活动 - &GT; getMedias()为$ MEDIA_COUNT =&GT; $媒体)?        &LT; IFRAME ID =内容SRC =htt​​p://www.mysite.com/media/view/id/<?php回声$媒体 - &GT;的getId();?&gt;中FRAMEBORDER =0的风格=宽度:100%;高度:825px;无缝=无缝&GT;
            &LT; P&GT;您的浏览器并不支援iframe。请升级到&lt; A HREF =htt​​p://getfirefox.com&gt;一种现代的浏览器和LT; / A&GT;&LT; / P&GT;
        &LT; / IFRAME&GT;

 

解决
这是code我用得到它的工作。我使用的Symfony 1.4。

 &LT; PHP的foreach($活动 - &GT; getMedias()为$ MEDIA_COUNT =&GT; $媒体)?        $ dataString = sfConfig ::的get('SF_ROOT_DIR')'/媒体/'.$媒体 - 方式&gt;的getLocation(); ?&GT;
        &LT; IMG SRC =数据:图像/ PNG; BASE64,&LT; PHP的回声base64_en code(的file_get_contents(../../../../../..\".$ dataString) );?&gt;中与GT;

 

解决方案

听起来你试图通过一个URL来READFILE,例如

  ReadFile的('http://example.com/foo/bar');

这会导致PHP来背启动一个全面的HTTP请求本身。您需要使用本地文件系统路径,例如

 用readfile('/路径/外/ DOC /根/为/的/ image.png');

这是一个纯粹的本地文件系统的操作,并且不涉及HTTP层可言,绕过整个文档根目录/ HTTP认证的企业。

I have a .png that I want to embed on a particular page. This .png is outside of the web root, but we have a module in our system that allows users to view that image on a separate page. I found that I can use an iframe to view the .png on some browsers, but sometimes there is an authorization issue or when trying to print the page the image doesn't load through the iframe. I tried PHPs readfile(), but then I just have another authorization issue. I find the authorization issue odd since one has to be logged in to use our site at all. What would be the best way to imbed this image?

<?php foreach($activity->getMedias() as $media_count => $media): 



        <iframe id="content" src="http://www.mysite.com/media/view/id/<?php echo $media->getId(); ?>" frameborder="0" style="width: 100%; height:825px;" seamless="seamless">
            <p>Your browser does not support iframes. Please upgrade to <a href="http://getfirefox.com">a modern browser</a>.</p>
        </iframe>

SOLVED This is the code I used to get it to work. I am using Symfony 1.4.

<?php foreach($activity->getMedias() as $media_count => $media): 

        $dataString=sfConfig::get('sf_root_dir').'/media/'.$media->getLocation(); ?>


        <img SRC="data:image/png;base64,<?php echo base64_encode(file_get_contents("../../../../../..".$dataString));?>">

解决方案

Sounds like you're trying to pass a url to readfile, e.g.

readfile('http://example.com/foo/bar');

This causes PHP to start up a full-blown HTTP request back to itself. You need to use a local file-system path, e.g.

readfile('/path/outside/doc/root/to/the/image.png');

That's a purely local filesystem operation, and does not involve the HTTP layer at all, bypassing the entire document root/http authentication business.

这篇关于如何查看Web根目录以外的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆