简体   繁体   English

用php脚本输出图像-src标签

[英]output an image with php script - src tag

I cannot output images on my web page on local host, 我无法在本地主机上的网页上输出图像,

I am using an images.php script, the last part is; 我正在使用images.php脚本,最后一部分是;

if ($mime) { 
           header('Content-type: '.$mime); 
           header('Content-length: '.filesize($pic)); 
           $file = @ fopen($pic, 'rb'); 
           if ($file) { 
                      fpassthru($file); 
                      exit;
                      }
           }

My other php page includes the below code; 我的其他php页面包含以下代码;

<li><a href="http://example.com" target="_blank"><img src="images.php?key=orn"></a></li>

However, all my images like the above are broken, I debugged my images.php file with if&else's and I saw that it comes to the end with true variables. 但是,我上面的所有图像都坏了,我用if&else调试了images.php文件,发现它的末尾包含了真正的变量。

How can I find the reason? 我如何找到原因?

fpassthru? fpassthru? grammer of src? src的语法? localhost? 本地主机? any other thing? 还有其他事吗?

$file = '../image.jpg';
$type = 'image/jpeg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
readfile($file);

You can also look into mod_xsendfile 您也可以查看mod_xsendfile

尝试显示来自 PHP 脚本的回显图像和 ` <img src="“…”`" tag< div><div id="text_translate"><p> 目标:</p><p> 1)我在 web 根目录之外有一个图像文件夹,其中放置了来自 web 应用程序的所有图像(每个图像路径都保存在数据库表中);</p><p> 2) 我想根据用户的请求获取该图像。</p><p> 很简单,对吧?</p><p> 我做了:</p><p> a) 创建一个 class 来读取图像(具有我记得的所有安全功能和保护措施)。 它(成功地)返回使用相应的 mime 类型编码(base64)的图像。</p><p> b) 出于演示目的,我创建了一个 index.php,它具有:</p><p> &lt;img src="agivenscript.php?img=name.jpeg"&gt;</p><p> 我在这里唯一的目标是从我的 web 应用程序中的任何其他地方调用一个脚本,该脚本输出具有相应 mime 类型的 base64 编码图像。</p><p> c) 创建了一个脚本“agivenscript.php”,它通过 GET 接收图像名称,实例化我的 class 并在一切顺利时获取 base64 编码图像。 然后它与图像相呼应。</p><p> 怎么了:</p><ul><li> 当我做 output - 使用 echo '&lt;img src="'. $output64encodedwithmimetype. '"&gt;'; - 在 agivenscript.php 中,它就像一个魅力;</li><li> 此外,如果我将 $output64encodedwithmimetype 内容直接放在 index.php 的 src 标记中,它也可以工作。</li><li> 但是,当我尝试&lt;img src="agivenscript.php?img=name.jpeg"&gt;时它不起作用。</li></ul><p> 由于 base64 编码的图像显然很好(并且具有 mime 类型),我错过了什么? 任何想法?</p><p> 预先感谢。</p></div> - Trying to display an echoed image from a PHP script in and `<img src=“…”` tag

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试显示来自 PHP 脚本的回显图像和 ` <img src="“…”`" tag< div><div id="text_translate"><p> 目标:</p><p> 1)我在 web 根目录之外有一个图像文件夹,其中放置了来自 web 应用程序的所有图像(每个图像路径都保存在数据库表中);</p><p> 2) 我想根据用户的请求获取该图像。</p><p> 很简单,对吧?</p><p> 我做了:</p><p> a) 创建一个 class 来读取图像(具有我记得的所有安全功能和保护措施)。 它(成功地)返回使用相应的 mime 类型编码(base64)的图像。</p><p> b) 出于演示目的,我创建了一个 index.php,它具有:</p><p> &lt;img src="agivenscript.php?img=name.jpeg"&gt;</p><p> 我在这里唯一的目标是从我的 web 应用程序中的任何其他地方调用一个脚本,该脚本输出具有相应 mime 类型的 base64 编码图像。</p><p> c) 创建了一个脚本“agivenscript.php”,它通过 GET 接收图像名称,实例化我的 class 并在一切顺利时获取 base64 编码图像。 然后它与图像相呼应。</p><p> 怎么了:</p><ul><li> 当我做 output - 使用 echo '&lt;img src="'. $output64encodedwithmimetype. '"&gt;'; - 在 agivenscript.php 中,它就像一个魅力;</li><li> 此外,如果我将 $output64encodedwithmimetype 内容直接放在 index.php 的 src 标记中,它也可以工作。</li><li> 但是,当我尝试&lt;img src="agivenscript.php?img=name.jpeg"&gt;时它不起作用。</li></ul><p> 由于 base64 编码的图像显然很好(并且具有 mime 类型),我错过了什么? 任何想法?</p><p> 预先感谢。</p></div> - Trying to display an echoed image from a PHP script in and `<img src=“…”` tag Zend Framework:img src标签中的PHP脚本导致图像损坏 - Zend Framework: PHP script in img src tag causing broken image 图像未使用 img src 标签显示在 php 中 - image not showing in php using img src tag 在标签中回显图像文件<img src="">在 php 中 - Echo image file in tag <img src=""> in php 使用php获取图像 - Get an image in php using the <img src=“” tag 将图像从img标签的src上传到php - Uploading Image from src of img tag to php 将php脚本放入图片标记的src中比正常速度慢多少? - Is putting a php script in the src of the image tag slower than normal and by how much? 所有图像src请求到php脚本 - All image src request to php script 在 PHP 图像上传后更新 HTML 中图像标签的 SRC - Update SRC of Image-Tag in HTML after PHP Image Upload 使用当前数据参数在img src标签中添加PHP脚本 - Add PHP script in img src tag with current data-parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM