我是小站长 發表於 2019-6-2 15:19:34

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

<br /><br />版本 dx 3.3<br /><br />估计3.4一样有这个问题,ie内核的浏览器下在上传后,缩略图都是显示xx。<br /><br />这个问题主要还是https下,对图片输出的时候 不能使用<br /><ol><li>dheader('Content-Type: image');</ol><br /><br />必须要明确到jpeg,png这里。<br /><br />在forum_image.php文件里59行左右<br />需要改为<br /><ol><li>dheader('Content-Type: image/jpeg');</ol>当然这个并不完美<br /><ol><li>if($img-&gt;Thumb($filename, $thumbfile, $w, $h, $type)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if($nocache) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;dheader('Content-Type: image/jpeg');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;@readfile($_G['setting']['attachdir'].$thumbfile);</ol><br /><br />这样会让png的图片无法显示出来。<br /><br />可以增加一个函数,来获取mime类型。<br /><br /><ol><li>function get_image_extension($image){<br /><li>&nbsp; &nbsp;&nbsp;&nbsp;$extension = pathinfo($filename,PATHINFO_EXTENSION);<br /><li>&nbsp; &nbsp;&nbsp;&nbsp;if(in_array($extension,['jpg','jpeg','png','gif','bmp'])){<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;return&nbsp;&nbsp;'image/'.$extension;<br /><li> }<br /><li>&nbsp; &nbsp; return 'image';<br /><li>}</ol>然后再去修改这个文件里输出的头部。<br />才可以彻底解决这个问题。<br /><br />php 5.3之后可以使用<br /><br /><ol><li>function get_image_extension($filename){<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$finfo = finfo_open(FILEINFO_MIME_TYPE);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$rs = '';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!$finfo) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;return 'image';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$rs = finfo_file($finfo, $filename);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;finfo_close($finfo);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return $rs;<br /><li>}</ol><br /><ol><li>&lt;?php<br /><li><br /><li>/**<br /><li> *&nbsp; &nbsp;&nbsp; &nbsp; (C)2001-2099 Comsenz Inc.<br /><li> *&nbsp; &nbsp;&nbsp; &nbsp;This is NOT a freeware, use is subject to license terms<br /><li> *<br /><li> *&nbsp; &nbsp;&nbsp; &nbsp;$Id: forum_image.php 32531 2013-02-06 10:15:19Z zhangguosheng $<br /><li> */<br /><li><br /><li>if(!defined('IN_DISCUZ') || empty($_GET['aid']) || empty($_GET['size']) || empty($_GET['key'])) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;header('location: '.$_G['siteurl'].'static/image/common/none.gif');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;exit;<br /><li>}<br /><li><br /><li>$nocache = !empty($_GET['nocache']) ? 1 : 0;<br /><li>$daid = intval($_GET['aid']);<br /><li>$type = !empty($_GET['type']) ? $_GET['type'] : 'fixwr';<br /><li>list($w, $h) = explode('x', $_GET['size']);<br /><li>$dw = intval($w);<br /><li>$dh = intval($h);<br /><li>$thumbfile = 'image/'.helper_attach::makethumbpath($daid, $dw, $dh);$attachurl = helper_attach::attachpreurl();<br /><li>function get_image_extension($filename){<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$finfo = finfo_open(FILEINFO_MIME_TYPE);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$rs = '';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!$finfo) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;return 'image';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$rs = finfo_file($finfo, $filename);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;finfo_close($finfo);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return $rs;<br /><li>}<br /><li><br /><li>if(!$nocache) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(file_exists($_G['setting']['attachdir'].$thumbfile)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; dheader('location: '.$attachurl.$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>}<br /><li><br /><li>define('NOROBOT', TRUE);<br /><li><br /><li>$id = !empty($_GET['atid']) ? $_GET['atid'] : $daid;<br /><li>if(dsign($id.'|'.$dw.'|'.$dh) != $_GET['key']) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');<br /><li>}<br /><li><br /><li>if($attach = C::t('forum_attachment_n')-&gt;fetch('aid:'.$daid, $daid, array(1, -1))) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(!$dw &amp;&amp; !$dh &amp;&amp; $attach['tid'] != $id) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if($attach['remote']) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; dheader('Content-Type: image');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; dheader('location: '.$_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'].'?imageView2/1/w/'.$dw.'/h/'.$dh.'/format/jpg/interlace/0/q/80');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;require_once libfile('class/image');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$img = new image;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if($img-&gt;Thumb($filename, $thumbfile, $w, $h, $type)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if($nocache) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$mine = get_image_extension($_G['setting']['attachdir'].$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;dheader('Content-Type: '.$mine);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;@readfile($_G['setting']['attachdir'].$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //echo file_get_contents($_G['setting']['attachdir'].$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;@unlink($_G['setting']['attachdir'].$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; } else {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;dheader('location: '.$attachurl.$thumbfile);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; dheader('Content-Type: image');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; @readfile($filename);<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>}<br /><li><br /><li>?&gt;</ol><br /><br />问题<em>, </em>这个<em>, </em>上传<em>, </em>显示<em>, </em>https

耗子 發表於 2019-6-2 19:08:38

感谢分享 干货!!

站长 發表於 2019-6-16 15:39:53

感谢分享。。

欣欣向荣 發表於 2022-12-1 05:13:21

水平tall
頁: [1]
查看完整版本: 解决https下IE上传图片不显示问题