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

jiangzhe8个月前学・知识307

解决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.                

  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. ?>

复制代码


相关文章

做网站,都有哪些重点

做网站,都有哪些重点

做网站都有哪些重点;好像这个问题,问的有点白痴,因为很多人都会说:环环相扣,都是重点好域名,好服务器,好程序,好设置!那要是企业网站建站有什么重点呢?那就是好的关键词,好的名称,好的用户体验那什么是好...

JS三元表达式

JS三元表达式

又叫三元运算符,必须有三个操作数参与的运算操作符号:? :表达式:在参与 js 程序时,都必须先计算出表达式结果,才能参与后续程序由于三元表达式具备了一些选择的效果,所以也是一种条件分支语句<s...

建站知识篇:PbootCMS小程序API的封装步骤教程

建站知识篇:PbootCMS小程序API的封装步骤教程

PbootCMS;一个开源的网站建设程序,适合有点基础的前端,稍微研究一下就会,就能给人建站,方便吧。别不多叙,书归正传,如何用pbootcms封包api下面是封装步骤(封装文件在文章提供下载,供大家...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。