dongmie3526 2013-06-20 07:20
浏览 23
已采纳

为什么要下载我的图像而不是在浏览器中查看?

Image Link for testing

When I click the clink, Chrome, Safari and FF all automatically download a file rather the view it in the browser. How can I make it viewable in the browser? Using the link and a img tag works fine, it's just when used directly that it forces a download.

PHP

// Figure the mime type
$mimetypes = array(
    'png' => 'image/png',
    'jpg' => 'image/jepg',
    'gif' => 'image/gif',
    'css' => 'text/css',
    'js' => 'application/x-javascript'
);
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$mime = "application/octet-stream";
if(array_key_exists($ext, $mimetypes)) {
    $mime = $mimetypes[$ext];
}

header('Content-Type: ' . $mime);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
readfile($filename);
  • 写回答

3条回答 默认 最新

  • duanjian9148 2013-06-20 07:32
    关注

    This line has an error:

    'jpg' => 'image/jepg', 
    

    It should be

    'image/jpeg'.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃