PHP头-内容类型:图像/jpeg -不为Internet Explorer工作。

时间:2021-12-16 11:45:40

We all hate Internet Explorer when building HTML templates, or modifying websites. Well I recently built a PHP image script to hide the location of the URL. It works fine for Firefox, Chrome and even Safari.

在构建HTML模板或修改网站时,我们都讨厌Internet Explorer。我最近建立了一个PHP图像脚本,用来隐藏URL的位置。它适用于Firefox、Chrome甚至Safari。

Internet Explorer refuses to display the image from the PHP script. It does not even give the broken image icons. Simply blank squares.

Internet Explorer拒绝显示来自PHP脚本的图像。它甚至没有给出破碎的图像图标。只是空白的方格。

Android also has the same issue, but I can get to that another time and might be related.

Android也有同样的问题,但我可以换个时间,可能会有关联。

Here is my code for the image script:

这是我的图像脚本的代码:

$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");

I searched high and low on Google and this website. Could not find a solid source explaining why Internet Explorer is not displaying the image.

我在谷歌和这个网站上搜索了很多。找不到可靠的来源解释为什么Internet Explorer没有显示图像。

Any help is greatly appreciated.

非常感谢您的帮助。

4 个解决方案

#1


8  

The Content-Type header name is written with an uppercase T. I am not sure if that is the issue, but some browsers might not recognize the Content-Type header when it is written with a lowercase t. Thus, you should use:

Content-Type头名称是用大写t写的。我不确定这是不是问题,但是有些浏览器可能在用小写t写的时候不能识别内容类型的头。因此,您应该使用:

header("Content-Type: image/jpeg");

Something else that might be a problem, is when you try to display an image that is not a jpeg, but a png or gif, while you give the image/jpeg content-type header. So, you should ensure that you give the correct content-type to the browser.

另一个问题可能是,当您试图显示一个不是jpeg的图像,而是一个png或gif图像时,当您给出图像/jpeg内容类型的标题时。因此,您应该确保将正确的内容类型提供给浏览器。

#2


2  

Internet explorer uses the mime type image/pjpeg. You use pjpeg for IE and jpeg for other browsers.

Internet explorer使用mime类型图像/pjpeg。您可以使用pjpeg为IE和jpeg提供其他浏览器。

header("Content-Type: image/pjpeg");

Source: image/pjpeg and image/jpeg

来源:图像/ pjpeg和图像/ jpeg

#3


0  

Set the content length header.

设置内容长度标题。

header("Content-Length: " . filesize($imagepath));

#4


-2  

I think i know what is the problem!

我想我知道是什么问题了!

IE expect you to use image/jpeg and not image/jpg. try this: Header("Content-Type: image/jpeg");

希望您使用图像/jpeg而不是图像/jpg。试试这个:标题(“内容类型:图像/ jpeg”);

in fact all browsers accpet this way! you don't have to worry anymore!

事实上,所有浏览器都是这样的!你不用再担心了!

#1


8  

The Content-Type header name is written with an uppercase T. I am not sure if that is the issue, but some browsers might not recognize the Content-Type header when it is written with a lowercase t. Thus, you should use:

Content-Type头名称是用大写t写的。我不确定这是不是问题,但是有些浏览器可能在用小写t写的时候不能识别内容类型的头。因此,您应该使用:

header("Content-Type: image/jpeg");

Something else that might be a problem, is when you try to display an image that is not a jpeg, but a png or gif, while you give the image/jpeg content-type header. So, you should ensure that you give the correct content-type to the browser.

另一个问题可能是,当您试图显示一个不是jpeg的图像,而是一个png或gif图像时,当您给出图像/jpeg内容类型的标题时。因此,您应该确保将正确的内容类型提供给浏览器。

#2


2  

Internet explorer uses the mime type image/pjpeg. You use pjpeg for IE and jpeg for other browsers.

Internet explorer使用mime类型图像/pjpeg。您可以使用pjpeg为IE和jpeg提供其他浏览器。

header("Content-Type: image/pjpeg");

Source: image/pjpeg and image/jpeg

来源:图像/ pjpeg和图像/ jpeg

#3


0  

Set the content length header.

设置内容长度标题。

header("Content-Length: " . filesize($imagepath));

#4


-2  

I think i know what is the problem!

我想我知道是什么问题了!

IE expect you to use image/jpeg and not image/jpg. try this: Header("Content-Type: image/jpeg");

希望您使用图像/jpeg而不是图像/jpg。试试这个:标题(“内容类型:图像/ jpeg”);

in fact all browsers accpet this way! you don't have to worry anymore!

事实上,所有浏览器都是这样的!你不用再担心了!