返回列表 发帖
查看: 4310|回复: 3

解决https下IE上传图片不显示问题

83

主题

-6

回帖

329

积分

炉火纯青

贡献
2 点
金币
241 个
发表于 2019-6-2 15:19:34 | 显示全部楼层 |阅读模式


版本 dx 3.3

估计3.4一样有这个问题,ie内核的浏览器下在上传后,缩略图都是显示xx。

这个问题主要还是https下,对图片输出的时候 不能使用
  1. dheader('Content-Type: image');
复制代码


必须要明确到jpeg,png这里。

在forum_image.php文件里59行左右
需要改为
  1. dheader('Content-Type: image/jpeg');
复制代码
当然这个并不完美
  1. if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
  2.                 if($nocache) {
  3.                         dheader('Content-Type: image/jpeg');
  4.                         @readfile($_G['setting']['attachdir'].$thumbfile);
复制代码


这样会让png的图片无法显示出来。

可以增加一个函数,来获取mime类型。

  1. function get_image_extension($image){
  2.      $extension = pathinfo($filename,PATHINFO_EXTENSION);
  3.      if(in_array($extension,['jpg','jpeg','png','gif','bmp'])){
  4.       return  'image/'.$extension;
  5. }
  6.     return 'image';
  7. }
复制代码
然后再去修改这个文件里输出的头部。
才可以彻底解决这个问题。

php 5.3之后可以使用

  1. function get_image_extension($filename){
  2.         $finfo = finfo_open(FILEINFO_MIME_TYPE);
  3.         $rs = '';
  4.         if (!$finfo) {
  5.             return 'image';
  6.         }
  7.         $rs = finfo_file($finfo, $filename);
  8.         finfo_close($finfo);
  9.         return $rs;
  10. }
复制代码

  1. <?php

  2. /**
  3. *      [Discuz!] (C)2001-2099 Comsenz Inc.
  4. *      This is NOT a freeware, use is subject to license terms
  5. *
  6. *      $Id: forum_image.php 32531 2013-02-06 10:15:19Z zhangguosheng $
  7. */

  8. if(!defined('IN_DISCUZ') || empty($_GET['aid']) || empty($_GET['size']) || empty($_GET['key'])) {
  9.         header('location: '.$_G['siteurl'].'static/image/common/none.gif');
  10.         exit;
  11. }

  12. $nocache = !empty($_GET['nocache']) ? 1 : 0;
  13. $daid = intval($_GET['aid']);
  14. $type = !empty($_GET['type']) ? $_GET['type'] : 'fixwr';
  15. list($w, $h) = explode('x', $_GET['size']);
  16. $dw = intval($w);
  17. $dh = intval($h);
  18. $thumbfile = 'image/'.helper_attach::makethumbpath($daid, $dw, $dh);$attachurl = helper_attach::attachpreurl();
  19. function get_image_extension($filename){
  20.         $finfo = finfo_open(FILEINFO_MIME_TYPE);
  21.         $rs = '';
  22.         if (!$finfo) {
  23.             return 'image';
  24.         }
  25.         $rs = finfo_file($finfo, $filename);
  26.         finfo_close($finfo);
  27.         return $rs;
  28. }

  29. if(!$nocache) {
  30.         if(file_exists($_G['setting']['attachdir'].$thumbfile)) {
  31.                 dheader('location: '.$attachurl.$thumbfile);
  32.         }
  33. }

  34. define('NOROBOT', TRUE);

  35. $id = !empty($_GET['atid']) ? $_GET['atid'] : $daid;
  36. if(dsign($id.'|'.$dw.'|'.$dh) != $_GET['key']) {
  37.         dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
  38. }

  39. if($attach = C::t('forum_attachment_n')->fetch('aid:'.$daid, $daid, array(1, -1))) {
  40.         if(!$dw && !$dh && $attach['tid'] != $id) {
  41.                dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
  42.         }
  43.         dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
  44.         if($attach['remote']) {
  45.                 $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
  46.                 dheader('Content-Type: image');
  47.                 dheader('location: '.$_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'].'?imageView2/1/w/'.$dw.'/h/'.$dh.'/format/jpg/interlace/0/q/80');
  48.                
  49.         } else {
  50.                 $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
  51.         }
  52.         require_once libfile('class/image');
  53.         $img = new image;
  54.         if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
  55.                 if($nocache) {
  56.                         $mine = get_image_extension($_G['setting']['attachdir'].$thumbfile);
  57.                         dheader('Content-Type: '.$mine);
  58.                         @readfile($_G['setting']['attachdir'].$thumbfile);
  59.                 //echo file_get_contents($_G['setting']['attachdir'].$thumbfile);
  60.                         @unlink($_G['setting']['attachdir'].$thumbfile);
  61.                 } else {
  62.                         dheader('location: '.$attachurl.$thumbfile);
  63.                 }
  64.         } else {
  65.                 dheader('Content-Type: image');
  66.                 @readfile($filename);
  67.         }
  68. }

  69. ?>
复制代码


回复

使用道具 举报

14

主题

1791

回帖

2058

积分

应用开发者

discuz 老兵

贡献
8 点
金币
188 个
QQ
发表于 2019-6-2 19:08:38 | 显示全部楼层
:lol感谢分享 干货!!
回复 支持 反对

使用道具 举报

1

主题

192

回帖

226

积分

炉火纯青

贡献
0 点
金币
32 个
发表于 2019-6-16 15:39:53 | 显示全部楼层
感谢分享。。
回复

使用道具 举报

0

主题

3

回帖

8

积分

初学乍练

贡献
0 点
金币
5 个
发表于 2022-12-1 05:13:21 | 显示全部楼层
水平tall
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 关注公众号
  • 有偿服务微信
  • 有偿服务QQ

手机版|小黑屋|Discuz! 官方交流社区 ( 皖ICP备16010102号 |皖公网安备34010302002376号 )|网站地图|star

GMT+8, 2024-4-26 11:15 , Processed in 0.048681 second(s), 6 queries , Redis On.

Powered by Discuz! W1.0 Licensed

Cpoyright © 2001-2024 Discuz! Team.

关灯 在本版发帖
有偿服务QQ
有偿服务微信
返回顶部
快速回复 返回顶部 返回列表