张丽梅 發表於 2023-8-21 00:00:00

DEDE图片集上传图片时出错显示(FILEID)的解决方法

<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>某日,某使用DeDe CMS v5.5的网站在后台上传<u>图片</u>时出现如下错误: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>作为web生手的我很是迷茫。印象里之前并没有做什么改动,于是百思不得其解。Google、百度、DeDe官网搜索了一大圈,发现有这个问题的人不少,但是没有一个给出解决的办法。只好自己试着分析分析…… </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>找到提示出错的相关js文件: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>/dede/handlers.js </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>发现有这么一段: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        function uploadSuccess(file, serverData) { <br>
        try { <br>
        var progress = new FileProgress(file, this.customSettings.upload_target); <br>
        if (serverData.substring(0, 7) === "FILEID:") { <br>
        addImage("swfupload.php?dopost=thumbnail&amp;id=" + serverData.substring(7), serverData.substring(7)); <br>
        progress.setStatus("获取缩略图..."); <br>
        progress.toggleCancel(false); <br>
        } else { <br>
        addImage("img/error.gif", 0); <br>
        progress.setStatus("有错误!"); <br>
        progress.toggleCancel(false); <br>
        alert(serverData); <br>
        } <br>
        } catch (ex) { <br>
        this.debug(ex); <br>
        } <br>
        } </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>其中: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        if (serverData.substring(0, 7) === "FILEID:") </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这句的判断为假导致如上图的问题。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>查看serverData的值没有发现什么异常,但是判断始终为假 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>问题就出在serverData.substring(0, 7) 始终都不等于"FILEID:" </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>调整了截取边界也一样有错,于是乎,请来了HttpAnalyzer一看,哦,原来如此: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>虽然这么看着没什么问题DEDE教程-AS<u>QQ</u>8.NET </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>但实际问题在这: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>前面多了三个字节:ef bb bf </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>大致一找原来这是utf-8的bom问题,是修改文件时在文件头自动加入的这三个字节导致的连锁反应 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>但是那么多文件要找出是哪个文件的问题倒是有点头大……网络资源网-ASQQ8.NET </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>后来找到一篇文章《转两篇 移除PHP中BOM的方法》按照其中给出的清除BOM的代码解决了这个问题 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>代码如下: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        &lt;?php <br>
        //remove the utf-8 boms <br>
        //by magicbug at gmail dot com <br>
        if (isset($_GET['dir'])){ //config the basedir <br>
        $basedir=$_GET['dir']; <br>
        }else{ <br>
        $basedir = '.'; <br>
        } <br>
        $auto = 1; <br>
        checkdir($basedir); <br>
        function checkdir($basedir){ <br>
        if ($dh = opendir($basedir)) { <br>
        while (($file = readdir($dh)) !== false) { <br>
        if ($file != '.' &amp;&amp; $file != '..'){ <br>
        if (!is_dir($basedir."/".$file)) { <br>
        echo "filename: $basedir/$file "; <br>
        echo checkBOM("$basedir/$file")." <br>
        "; <br>
        }else{ <br>
        $dirname = $basedir."/".$file; <br>
        checkdir($dirname); <br>
        } <br>
        } <br>
        } <br>
        closedir($dh); <br>
        } <br>
        } <br>
        function checkBOM ($filename) { <br>
        global $auto; <br>
        $contents = file_get_contents($filename); <br>
        $charset = substr($contents, 0, 1); <br>
        $charset = substr($contents, 1, 1); <br>
        $charset = substr($contents, 2, 1); <br>
        if (ord($charset) == 239 &amp;&amp; ord($charset) == 187 &amp;&amp; ord($charset) == 191) { <br>
        if ($auto == 1) { <br>
        $rest = substr($contents, 3); <br>
        rewrite ($filename, $rest); <br>
        return ("&lt;font color=red&gt;BOM found, automatically removed.&lt;/font&gt;"); <br>
        } else { <br>
        return ("&lt;font color=red&gt;BOM found.&lt;/font&gt;"); <br>
        } <br>
        } <br>
        else return ("BOM Not Found."); <br>
        } <br>
        function rewrite ($filename, $data) { <br>
        $filenum = fopen($filename, "w"); <br>
        flock($filenum, LOCK_EX); <br>
        fwrite($filenum, $data); <br>
        fclose($filenum); <br>
        } <br>
        ?&gt;保存为a.php,放在网站根目录访问下就可以了。 <br>
        ps:如果在访问a.php的时候报错如: <br>
        PHP Fatal error: Allowed memory size of 134217728 bytes exhausted <br>
        那就试用下面的修改版检查出有bom的文件自己修改吧 <br>
        &lt;?php <br>
        //remove the utf-8 boms <br>
        //by magicbug at gmail dot com <br>
        if (isset($_GET['dir'])){ //config the basedir <br>
        $basedir=$_GET['dir']; <br>
        }else{ <br>
        $basedir = '.'; <br>
        } <br>
        $auto = 1; <br>
        checkdir($basedir); <br>
        echo ("<br>
        &lt;font color=green&gt;completed!&lt;/font&gt;<br>
        "); <br>
        function checkdir($basedir) <br>
        { <br>
        if ($dh = opendir($basedir)) <br>
        { <br>
        while (($file = readdir($dh)) !== false) <br>
        { <br>
        if ($file != '.' &amp;&amp; $file != '..') <br>
        { <br>
        if (!is_dir($basedir."/".$file)) <br>
        { <br>
        //echo "filename: $basedir/$file "; <br>
        checkBOM("$basedir/$file"); <br>
        } <br>
        else <br>
        { <br>
        $dirname = $basedir."/".$file; <br>
        checkdir($dirname); <br>
        } <br>
        } <br>
        } <br>
        closedir($dh); <br>
        } <br>
        } <br>
        function checkBOM ($filename) { <br>
        global $auto; <br>
        $contents = file_get_contents($filename,NULL,NULL,0,10); <br>
        $charset = substr($contents, 0, 1); <br>
        $charset = substr($contents, 1, 1); <br>
        $charset = substr($contents, 2, 1); <br>
        if (ord($charset) == 239 &amp;&amp; ord($charset) == 187 &amp;&amp; ord($charset) == 191) { <br>
        if ($auto == 1) { <br>
        //$rest = substr($contents, 3); <br>
        //rewrite ($filename, $rest); <br>
        echo ($filename."--------"."&lt;font color=red&gt;BOM found&lt;/font&gt;<br>
        "); <br>
        } else { <br>
        //return ("&lt;font color=red&gt;BOM found.&lt;/font&gt;"); <br>
        } <br>
        } <br>
        //else return ("BOM Not Found."); <br>
        } <br>
        function rewrite ($filename, $data) { <br>
        $filenum = fopen($filename, "w"); <br>
        flock($filenum, LOCK_EX); <br>
        fwrite($filenum, $data); <br>
        fclose($filenum); <br>
        } <br>
        ?&gt; </p>
頁: [1]
查看完整版本: DEDE图片集上传图片时出错显示(FILEID)的解决方法