• 源码铺子 欢迎您

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

分类:技术教程 时间:2023-03-12 14:02 浏览:227
概述
解决https下IE上传图片不显示问题版本 dx 3.3估计3.4一样有这个问题,ie内核的浏览器下在上传后,缩略图都是显示xx。这个问题主要还是https下,对图片输出的时候 不能使用dheader(‘Content-Type: image’);必须要明确到jpeg,png这里。在forum_image.php文件里59行左右需要改为dheader(‘Content-Type: image/jpeg’);复制代码当然这个并不完美if(
内容

解决https下IE上传图片不显示问题
版本 dx 3.3
估计3.4一样有这个问题,ie内核的浏览器下在上传后,缩略图都是显示xx。
这个问题主要还是https下,对图片输出的时候 不能使用
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.         } else {

  49.                 $filename = $_G[‘setting’][‘attachdir’].’forum/’.$attach[‘attachment’];

  50.         }

  51.         require_once libfile(‘class/image’);

  52.         $img = new image;

  53.         if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {

  54.                 if($nocache) {

  55.                         $mine = get_image_extension($_G[‘setting’][‘attachdir’].$thumbfile);

  56.                         dheader(‘Content-Type: ‘.$mine);

  57.                         @readfile($_G[‘setting’][‘attachdir’].$thumbfile);

  58.                 //echo file_get_contents($_G[‘setting’][‘attachdir’].$thumbfile);

  59.                         @unlink($_G[‘setting’][‘attachdir’].$thumbfile);

  60.                 } else {

  61.                         dheader(‘location: ‘.$attachurl.$thumbfile);

  62.                 }

  63.         } else {

  64.                 dheader(‘Content-Type: image’);

  65.                 @readfile($filename);

  66.         }

  67. }


  68. ?>


评论
资讯正文页右侧广告
点击排行
源码铺子
网站首页| 关于我们| 广告合作| 联系我们| 隐私条款| 免责声明| 网站地图
CopyRight ©  2020- 源码铺子-www.shopet.cn源码铺子川公网安备51068202000248号 蜀ICP备20020328号-1
本站所有资源来源于互联网,仅用于学习及参考使用,切勿用于商业用途,如产生法律纠纷本站概不负责!
资源除标明原创外均来自网络转载,版权归原作者所有,若侵犯到您权益请联系我们删除,我们将及时处理!若您需使用非免费的软件或服务,请购买正版授权并合法使用!
本站支持http/3及IPV6访问! 本站支持http/3及IPV6访问!
浏览记录
联系客服
平台客服1 平台客服2 工作时间
09:00 - 21:00
手机版
源码铺子
扫一扫进手机版
返回顶部