久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

返回列表 發帖
查看: 5436|回復: 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. ?>
復制代碼


回復

使用道具 舉報

15

主題

1868

回帖

2164

積分

應用開發者

discuz 老兵

貢獻
11 點
金幣
198 個
QQ
沙發
發表于 2019-6-2 19:08:38 | 只看Ta
:lol感謝分享 干貨!!
回復

使用道具 舉報

1

主題

192

回帖

226

積分

爐火純青

貢獻
0 點
金幣
32 個
板凳
發表于 2019-6-16 15:39:53 | 只看Ta
感謝分享。。
回復

使用道具 舉報

0

主題

3

回帖

8

積分

初學乍練

貢獻
0 點
金幣
5 個
地板
發表于 2022-12-1 05:13:21 | 只看Ta
水平tall
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

  • 關注公眾號
  • 有償服務微信
  • 有償服務QQ

手機版|小黑屋|Discuz! 官方交流社區 ( 皖ICP備16010102號 |皖公網安備34010302002376號 )|網站地圖|star

GMT+8, 2025-9-18 17:36 , Processed in 0.075099 second(s), 29 queries .

Powered by Discuz! W1.0 Licensed

Copyright © 2001-2025 Discuz! Team.

關燈 在本版發帖
有償服務QQ
有償服務微信
返回頂部
快速回復 返回頂部 返回列表