DEDECMS织梦模板建站图片集上传图片时出错显示
发布于:2018-03-11 08:31  浏览:

找到提示出错的相关js文件:
/dede/handlers.js
发现有这么一段:

复制代码
代码如下:

function uploadSuccess(file, serverData) {
try {
var progress = new FileProgress(file, this.customSettings.upload_target);
if (serverData.substring(0, 7) === "FILEID:") {
addImage("swfupload.php?dopost=thumbnail&id=" + serverData.substring(7), serverData.substring(7));
progress.setStatus("获取缩略图...");
progress.toggleCancel(false);
} else {
addImage("img/error.gif", 0);
progress.setStatus("有错误!");
progress.toggleCancel(false);
alert(serverData);
}
} catch (ex) {
this.debug(ex);
}
}

其中:

复制代码
代码如下:

if (serverData.substring(0, 7) === "FILEID:")

这句的判断为假导致如上图的问题。
查看serverData的值没有发现什么异常,但是判断始终为假
问题就出在serverData.substring(0, 7) 始终都不等于"FILEID:"
调整了截取边界也一样有错,于是乎,请来了HttpAnalyzer一看,哦,原来如此:
虽然这么看着没什么问题DEDE教程-ASQQ8.NET
但实际问题在这:
前面多了三个字节:ef bb bf
大致一找原来这是utf-8的bom问题,是修改文件时在文件头自动加入的这三个字节导致的连锁反应
但是那么多文件要找出是哪个文件的问题倒是有点头大……网络资源网-ASQQ8.NET
后来找到一篇文章《转两篇 移除PHP中BOM的方法》按照其中给出的清除BOM的代码解决了这个问题
代码如下:

复制代码
代码如下:

<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET['dir'])){ //config the basedir
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ";
echo checkBOM("$basedir/$file")."
";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("<font color=red>BOM found, automatically removed.</font>");
} else {
return ("<font color=red>BOM found.</font>");
}
}
else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>保存为a.php,放在网站根目录访问下就可以了。
ps:如果在访问a.php的时候报错如:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
那就试用下面的修改版检查出有bom的文件自己修改吧
<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET['dir'])){ //config the basedir
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
echo ("
<font color=green>completed!</font>
");
function checkdir($basedir)
{
if ($dh = opendir($basedir))
{
while (($file = readdir($dh)) !== false)
{
if ($file != '.' && $file != '..')
{
if (!is_dir($basedir."/".$file))
{
//echo "filename: $basedir/$file ";
checkBOM("$basedir/$file");
}
else
{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename,NULL,NULL,0,10);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
//$rest = substr($contents, 3);
//rewrite ($filename, $rest);
echo ($filename."--------"."<font color=red>BOM found</font>
");
} else {
//return ("<font color=red>BOM found.</font>");
}
}
//else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>


推荐内容