PHP标头 - 内容类型:image / jpeg - 不适用于Internet Explorer [英] PHP Header - Content-type: image/jpeg - Not working for Internet Explorer

查看:118
本文介绍了PHP标头 - 内容类型:image / jpeg - 不适用于Internet Explorer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



Internet Explorer拒绝显示来自PHP脚本的图像。它甚至不会提供破碎的图像图标。简单的空白正方形。



Android也有同样的问题,但我可以再次尝试,并且可能会有相关性。



这是我的图像脚本代码:

  $ image_id = $ _GET ['id']; 

包含mysql_connect.php;
$ sql =SELECT * FROM images WHERE code ='$ image_id';
$ result = mysql_query($ sql);
$ r = mysql_fetch_array($ result);

$ imagepath = $ r ['path'];

//制作合适的图片
header(Content-type:image / jpeg);

echo file_get_contents($ imagepath);

我在Google和本网站上搜索了高低版本。



非常感谢任何帮助。



  header(Content-Type:image / jpeg); 

当您尝试显示不是jpeg的图像时,可能会出现其他问题,而是一个PNG或GIF,而你给图像/ jpeg内容类型的标题。所以,你应该确保你给浏览器提供正确的内容类型。


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.

Internet Explorer refuses to display the image from the PHP script. 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.

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.

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. 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. So, you should ensure that you give the correct content-type to the browser.

这篇关于PHP标头 - 内容类型:image / jpeg - 不适用于Internet Explorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆