使用readfile和file_get_contents损坏的映像

mgv*_*513 5 php image file-get-contents readfile

我正在尝试使用一个函数来实现这个功能:

<img src='login.php?image=ind_legend.jpg'>
Run Code Online (Sandbox Code Playgroud)

但我不能通过功能来放置图像.我回过头几步,只尝试了这部分代码:

<?php
$file = "http://localhost/sales/test.jpg";
header('Content-type: image/jpeg');
readfile($file);
?>
Run Code Online (Sandbox Code Playgroud)

或使用此功能:

echo file_get_contents($source);
Run Code Online (Sandbox Code Playgroud)

但事实是,我唯一得到的是一个破碎的图像交叉(IE)或在Firefox中没有.

我将不胜感激任何建议

提前致谢

小智 12

readfile()之前使用php 的ob_clean()函数


mar*_*rio 6

你的PHP脚本中肯定有一些空格,或者UTF-8 BOM<?php开始标记之前有一些空白.使用hexeditor找出答案.

要进一步调试,直接在浏览器中打开图像URL http://localhost/login.php?image = ind_legend.jpg,然后保存文件.然后将其与原始JPEG进行比较.