查看: 90|回复: 3

[教程] 解决https下IE上传图片不显示问题

[复制链接]

69

主题

8

回帖

0

积分

热心网友

金币
8
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-1-9
发表于 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. ?>


问题, 这个, 上传, 显示, https
回复

使用道具 举报

11

主题

413

回帖

0

积分

热心网友

金币
413
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-11-29
发表于 2019-6-2 19:08:38 | 显示全部楼层
感谢分享 干货!!
回复

使用道具 举报

0

主题

85

回帖

10

积分

技术1级

金币
95
阅读权限
10
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-4-30
发表于 2019-6-16 15:39:53 | 显示全部楼层
感谢分享。。
回复

使用道具 举报

0

主题

1

回帖

0

积分

热心网友

金币
1
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2012-2-20
发表于 2022-12-1 05:13:21 | 显示全部楼层
水平tall
回复

使用道具 举报

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

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部