易仿帝国yfdiguo.com

您当前的位置:首页 > 问题库

帝国CMS实现上传附件名为源文件名+随机码的方法

zcmcss发表于2017-12-11问题库
示例:
原文件名:测试下载.rar
上传后,自动更名为:测试下载_9df430c26057400fca4a07bec9db3b62.rar

修改方法:
打开文件 /e/class/connect.php 文件
查找:
$r[filetype]=GetFiletype($file_name);
在下面一行加入以下代码:
$filename2=str_replace($r[filetype], '', $file_name); //获得去掉后缀的文件名
$mytype = array (".txt", ".rar", ".zip", ".gif", ".jpg", ".png", ".swf");//定义需要保留原名的文件类型

查找:
$r[filename]=$r[insertfile].$r[filetype];
修改为:
if(in_array($r[filetype],$mytype)){
$r[filename]=$filename2."_".$r[insertfile].$r[filetype];//将真实文件名加在随机码的前面中间以_分隔
}
else
{
$r[filename]=$r[insertfile].$r[filetype];
}

修改完成

说明:
$mytype = array (“.txt”, “.rar”, “.zip”);
这一句就是定义哪些文件类型需要加上源文件名的。

也可以在文件名前面加上指定名称,如网站域名
if(in_array($r[filetype],$mytype)){
$r[filename]="cmsjzy.cn_".$filename2."_".$r[insertfile].$r[filetype];//将真实文件名加在随机码的前面中间以_分隔
}
else
{
$r[filename]=$r[insertfile].$r[filetype];
}

热门问题

©2017 易仿帝国yfdiguo.com


友情链接: 阿里云优惠网| 阿里云推荐码| 阿里云教程| 莫愁博客|
♥ www.yfdiguo.com
联系作者QQ: