在构建 HTML 模板或修改网站时,我们都讨厌 Internet Explorer。好吧,我最近构建了一个 PHP 图像脚本来隐藏 URL 的位置。它适用于 Firefox、Chrome 甚至 Safari。
Internet Explorer 拒绝显示来自 PHP 脚本的图像。它甚至不提供损坏的图像图标。只是空白方 block 。
Android 也有同样的问题,但我可以改天再说,可能是相关的。
这是我的图像脚本代码:
$image_id = $_GET['id'];
include "mysql_connect.php";
$sql = "SELECT * FROM images WHERE code='$image_id'";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);
$imagepath=$r['path'];
// Produce proper Image
header("Content-type: image/jpeg");
echo file_get_contents("$imagepath");
我在 Google 和这个网站上进行了高低搜索。无法找到可靠的来源来解释 Internet Explorer 不显示图像的原因。
非常感谢任何帮助。
最佳答案
Content-Type header 名称以大写 T 书写。我不确定这是否是问题所在,但某些浏览器可能无法识别以小写 t 书写的 Content-Type header 。因此,您应该使用:
header("Content-Type: image/jpeg");
当您尝试显示不是 jpeg 而是 png 或 gif 的图像时,可能会出现其他问题,同时您提供 image/jpeg 内容类型 header 。因此,您应该确保为浏览器提供正确的内容类型。
关于PHP header - 内容类型 : image/jpeg - Not working for Internet Explorer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14148586/