readfile 和 file_get_contents 损坏的图像
我正在尝试使用一个函数来实现此功能:
<img src='login.php?image=ind_legend.jpg'>
但我无法通过该函数来放置图像。我返回了几个步骤,只尝试了这部分代码:
<?php
$file = "http://localhost/sales/test.jpg";
header('Content-type: image/jpeg');
readfile($file);
?>
或使用此函数:
echo file_get_contents($source);
但事实是,我得到的唯一结果是图像交叉(IE)损坏,或者在 Firefox 中什么也没有。
我将不胜感激任何建议
提前致谢
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);
?>
or using this function:
echo file_get_contents($source);
but the fact is that the only thing I get is a broken image cross (IE) or nothing in Firefox.
I would appreciate any suggestions
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在readfile()之前使用php的ob_clean()函数
use the ob_clean() function of php before the readfile()
您的 PHP 脚本中肯定有一些空格,或者
UTF-8 BOM
在开始标记之前不可见。使用十六进制编辑器来找出答案。
要进一步调试,请打开图像 URL http://localhost/login.php?image=ind_legend。 jpg 直接在浏览器中保存文件。然后将其与原始 JPEG 进行比较。
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.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.
如前所述,您可能有一些空白。我会尝试用下面的代码替换整个文件。删除结束 php 语句可以消除任何出现额外空格的可能性:
As previously mentioned, you probably have some whitespace. I'd try replacing the entire file with the code below. Removing the closing php statement eliminates any chance that there is extra whitespace:
首先将您的浏览器指向 http://youraddress/login.php?image=ind_legend.jpg< /a> 并检查结果。
也许文件 /sales/test.jpg 已损坏,或者您没有为 readline 启用 http:// 包装器
最后通过您选择的浏览器的将图像另存为...上下文菜单选项保存损坏的图像并尝试用文本编辑器打开它。如果您发现错误消息(如果您启用了它们),我不会感到惊讶。
first of all point your browser to http://youraddress/login.php?image=ind_legend.jpg and check the result.
Maybe the file /sales/test.jpg is corrupted or you don't have enabled the http:// wrapper for readline
At last save the corrupted image via the save image as... context menu option of your browser of choice and try to open it with a text editor. I will not surprised if you will find an error message (if you have them enabled).