欢迎光临
我们一直在努力

DEDECMS5.7 UTF_8版本上传文件重命名为中文乱码的解决办法

虽然一直在使用织梦建站,但是自己且很少使用他的功能。今天一个朋友突然说网站出问题了。在上传文件的时候如果重新设置中文名就出现乱码和无法打开的问题。我打开自己的后台一看也出现了这个问题。

忙活了一阵,终于搞定了。现在把他分享出来:

第一步:找到\include\dialog\select_soft_post.php 替换为下面的内容

< ?php
if(!isset($cfg_basedir))
{
	include_once(dirname(__FILE__).'/config.php');
}
if(empty($uploadfile)) $uploadfile = '';
if(empty($uploadmbtype)) $uploadmbtype = '软件类型';
if(empty($bkurl)) $bkurl = 'select_soft.php';
$newname = ( empty($newname) ? '' : ereg_replace("[\\ \"\*\?\t\r\n<>':/|]", "", $newname) );

if(!is_uploaded_file($uploadfile))
{
	ShowMsg("你没有选择上传的文件或选择的文件大小超出限制!", "-1");
	exit();
}

//软件类型所有支持的附件
$cfg_softtype = $cfg_softtype;
$cfg_softtype = str_replace('||', '|', $cfg_softtype);
$uploadfile_name = trim(ereg_replace("[ \r\n\t\*\%\\/\?>< \|\":]{1,}",'',$uploadfile_name));
if(!eregi("\.(".$cfg_softtype.")", $uploadfile_name))
{
	ShowMsg("你所上传的{$uploadmbtype}不在许可列表,请更改系统对扩展名限定的配置!","");
	exit();
}

$nowtme = time();
if($activepath==$cfg_soft_dir)
{
	$newdir = MyDate($cfg_addon_savetype, $nowtme);
	$activepath = $activepath.'/'.$newdir;
	if(!is_dir($cfg_basedir.$activepath))
	{
		MkdirAll($cfg_basedir.$activepath,$cfg_dir_purview);
		CloseFtp();
	}
}

//文件名(前为手工指定, 后者自动处理)
if(!empty($newname))
{
	$filename = $newname;
	if(!ereg("\.", $filename)) $fs = explode('.', $uploadfile_name);
	else $fs = explode('.', $filename);
	if(eregi($cfg_not_allowall, $fs[count($fs)-1]))
	{
		ShowMsg("你指定的文件名被系统禁止!",'javascript:;');
		exit();
	}
	if(!ereg("\.", $filename)) $filename = $filename.'.'.$fs[count($fs)-1];
}else{
	$filename = $cuserLogin->getUserID().'-'.dd2char(MyDate('ymdHis',$nowtme));
	$fs = explode('.', $uploadfile_name);
	if(eregi($cfg_not_allowall, $fs[count($fs)-1]))
	{
		ShowMsg("你上传了某些可能存在不安全因素的文件,系统拒绝操作!",'javascript:;');
		exit();
	}
	$filename = $filename.'.'.$fs[count($fs)-1];
}

$fullfilename = $cfg_basedir.$activepath.'/'.$filename;
$fullfileurl = $activepath.'/'.$filename;
$fullfilename  = mb_convert_encoding($fullfilename,'GBK','UTF-8');
 //fullname也是GBK编码,页面是UTF-8,所以需要把上传失败提示转为UTF-8
$failupload = mb_convert_encoding($fullfilename,'UTF-8','GBK');
move_uploaded_file($uploadfile,$fullfilename) or die("上传文件到".$failupload."失败!");
//再把文件名从GBK转为UTF-8,用于保存到数据库
$$fullfilename = mb_convert_encoding($fullfilename,'UTF-8','GBK'); 
@unlink($uploadfile);
if($cfg_remote_site=='Y' && $remoteuploads == 1)
{
	//分析远程文件路径
	$remotefile = str_replace(DEDEROOT, '', $fullfilename);
	$localfile = '../..'.$remotefile;
	//创建远程文件夹
	$remotedir = preg_replace('/[^\/]*\.('.$cfg_softtype.')/', '', $remotefile);
	$ftp->rmkdir($remotedir);
	$ftp->upload($localfile, $remotefile);
}

if($uploadfile_type == 'application/x-shockwave-flash')
{
	$mediatype=2;
}
else if(eregi('image',$uploadfile_type))
{
	$mediatype=1;
}
else if(eregi('audio|media|video',$uploadfile_type))
{
	$mediatype=3;
}
else
{
	$mediatype=4;
}

$inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
   VALUES ('0','$filename','$fullfileurl','$mediatype','0','0','0','{$uploadfile_size}','{$nowtme}','".$cuserLogin->getUserID()."'); ";

$dsql->ExecuteNoneQuery($inquery);
$fid = $dsql->GetLastID();
AddMyAddon($fid, $fullfileurl);

ShowMsg("成功上传文件!",$bkurl."?comeback=".urlencode($filename)."&f=$f&activepath=".urlencode($activepath)."&d=".time());
exit();
?>

返回文件列表页面修改 找到 \include\dialog\select_soft.php 替换为:

< ?php
require_once(dirname(__FILE__)."/config.php");
if(empty($activepath))
{
	$activepath = '';
}
$activepath = str_replace('.','',$activepath);
$activepath = ereg_replace("/{1,}",'/',$activepath);
if(strlen($activepath) < strlen($cfg_soft_dir))
{
	$activepath = $cfg_soft_dir;
}
$inpath = $cfg_basedir.$activepath;
$activeurl = '..'.$activepath;
if(empty($f))
{
	$f='form1.enclosure';
}

if(empty($comeback))
{
	$comeback = '';
}

?>
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:枫叶博客 » DEDECMS5.7 UTF_8版本上传文件重命名为中文乱码的解决办法

分享到: 生成海报
avatar

热门文章

  • 评论 10

    Captcha Code

    • QQ号
    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址
    1. #1
      avatar

      我也主要用的wp

      包容天下13年前 (2011-11-20)国内网友回复
    2. #2
      avatar

      独立博客大全邀请你的加入,免费收录

      西安SEO13年前 (2011-11-22)国内网友回复
    3. #3
      avatar

      最开始的时候我也用dede后来就改成wp了

      雷依依13年前 (2011-11-22)国内网友回复
    4. #4
      avatar

      有点复杂!看不懂。。还是支持下。。

      药油13年前 (2011-11-23)国内网友回复
    5. #5
      avatar

      没说这种是什么原因造成的吗? 现在感觉 5.7 怎么好垃圾呢

      团购网站大全12312年前 (2011-11-23)国内网友回复
    6. #6
      avatar

      还好我用的一直是GBK版本的,不过dedecms漏洞太多了

      青梅煮酒12年前 (2011-11-25)国内网友回复
    7. #7
      avatar

      还好我用的一直是GBK版本的,不过dedecms漏洞太多了

      Ralph Lauren+Outlet+Online12年前 (2011-11-26)国内网友回复
    8. #8
      avatar

      博主你的网站做的不错哦。最近闲来无事,我写了一篇小说–打篮球的女孩。在起点上,有时间了帮我顶一下哦!!!!

      打篮球的女孩12年前 (2012-02-29)国内网友回复
    9. #9
      avatar

      博主您好,我这有个交流群,是关于搜索引擎优化的,大家在一起交流网站排名,提高网站权重PR,希望您能加入,QQ群号:207057381

      百度12年前 (2012-04-16)国内网友回复
    10. #10
      avatar

      不错!有用!顶一下!

      敏思语文10年前 (2014-06-17)国内网友回复

    枫叶博客

    联系我们联系我们

    登录

    忘记密码 ?