使用readfile和file_get_contents损坏的映像 [英] Broken image with readfile and file_get_contents
问题描述
我正在尝试使用一个函数来实现这个功能:
I'm trying to use a function in order to get this working:
<img src='login.php?image=ind_legend.jpg'>
但是我无法通过函数来放置图像。我回过头几步,只尝试了这部分代码:
But I can't pass through the function to place the image. I went back a couple of steps and tried only this part of the code:
<?php
$file = "http://localhost/sales/test.jpg";
header('Content-type: image/jpeg');
readfile($file);
?>
或使用此功能:
echo file_get_contents($source);
但事实是,我唯一得到的是图像交叉(IE)或者没有任何内容Firefox。
but the fact is that the only thing I get is a broken image cross (IE) or nothing in Firefox.
我将不胜感激任何建议
提前致谢
推荐答案
你的PHP脚本中肯定有一些空格,或者 UTF-8 BOM
在您的<?php
开放之前无形标记。使用hexeditor查找。
You certainly have some whitespace in your PHP script, or a UTF-8 BOM
invisibly before your <?php
opening marker. Use a hexeditor to find out.
要进一步调试,请打开图像URL http://localhost/login.php?image = ind_legend.jpg 直接在浏览器中保存文件。然后将其与原始JPEG进行比较。
To debug it further, open the image URL http://localhost/login.php?image=ind_legend.jpg directly in your browser, save the file. And then compare it to the original JPEG.
这篇关于使用readfile和file_get_contents损坏的映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!