简体   繁体   English

PHP 标头 - 内容类型:图像/jpeg - 不适用于 Internet Explorer

[英]PHP Header - Content-type: image/jpeg - Not working for Internet Explorer

We all hate Internet Explorer when building HTML templates, or modifying websites.在构建 HTML 模板或修改网站时,我们都讨厌 Internet Explorer。 Well I recently built a PHP image script to hide the location of the URL.好吧,我最近构建了一个 PHP 图像脚本来隐藏 URL 的位置。 It works fine for Firefox, Chrome and even Safari.它适用于 Firefox、Chrome 甚至 Safari。

Internet Explorer refuses to display the image from the PHP script. Internet Explorer 拒绝显示来自 PHP 脚本的图像。 It does not even give the broken image icons.它甚至不提供损坏的图像图标。 Simply blank squares.简单的空白方块。

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.任何帮助是极大的赞赏。

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. Content-Type 标头名称用大写 T 书写。我不确定这是否是问题所在,但某些浏览器在使用小写 t 书写时可能无法识别 Content-Type 标头。 Thus, you should use:因此,您应该使用:

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.其他可能有问题的地方是,当您尝试显示不是 jpeg 而是 png 或 gif 的图像时,同时提供了 image/jpeg 内容类型标题。 So, you should ensure that you give the correct content-type to the browser.因此,您应该确保为浏览器提供正确的内容类型。

Internet explorer uses the mime type image/pjpeg . Internet Explorer 使用 mime 类型image/pjpeg You use pjpeg for IE and jpeg for other browsers. IE 使用pjpeg ,其他浏览器使用jpeg

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

Source: image/pjpeg and image/jpeg来源: 图像/pjpeg 和图像/jpeg

设置内容长度标题。

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

I think I know what the problem is.我想我知道问题是什么。

Internet Explorer expects you to use image/jpeg and not image/jpg. Internet Explorer 希望您使用 image/jpeg 而不是 image/jpg。

Try this:试试这个:

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

All browsers accept this format, and you won't have to worry anymore.所有浏览器都接受这种格式,您不必再担心了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标头(“ Content-Type:图片/ jpeg”)不起作用 - header(“Content-Type: image/jpeg”) not working header(Content-type:image / jpeg)无法正常工作 - header(Content-type: image/jpeg) not working php header('Content-type:image / jpeg')显示损坏的图像 - php header('Content-type: image/jpeg') shows borken image PHP标题内容类型图像/ JPEG安全问题 - php header content-type image/jpeg security question PHP标头('Content-Type:image / jpeg')在localhost上有效,但在真实服务器上不可用 - PHP header('Content-Type : image/jpeg') works on localhost but not working on real server header(“Content-type:text / css”);正在使用Firefox和Chrome,但在Internet Explorer 9中它显示为“text / html” - header(“Content-type: text/css”); is working in Firefox and Chrome, but in Internet Explorer 9 it shows up as 'text/html' 使用PHP来“解析”带有响应标题“ content-type:image / jpeg”的图像 - Use PHP to “parse” image with response header “content-type: image/jpeg” header('Content-Type: image/jpeg') 不适用于 Firefox - header('Content-Type: image/jpeg') doesn't work with Firefox header('Content-Type:image / jpeg')将页面空白 - header('Content-Type: image/jpeg') turns page blank 内容类型:图片/ jpeg无法在本地实时运行 - Content-Type: image/jpeg not working on live working on local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM