Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已解决] 【解决】https下IE上传图片不显示问题

[复制链接]
bugx 发表于 2018-12-17 19:22:10 | 显示全部楼层 |阅读模式
本帖最后由 bugx 于 2018-12-17 19:23 编辑

版本 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. }
复制代码
然后再去修改这个文件里输出的头部。
才可以彻底解决这个问题。

评分

1

查看全部评分

 楼主| bugx 发表于 2018-12-19 11:04:35 | 显示全部楼层
本帖最后由 bugx 于 2018-12-19 11:13 编辑

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. }
复制代码
回复

使用道具 举报

 楼主| bugx 发表于 2018-12-19 11:29:16 | 显示全部楼层
  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. ?>
复制代码


回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-13 12:32 , Processed in 0.201683 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表