FCKeditor 版本 2.6.4.1Build 23187
FCKeditor上传文件是不会重命名的,除非是有崇明文件存在。例如:当上传第二个“0104_p5.jpg”图片时,FCKeditor就会将新文件重命名为“0104_p5(1).jpg”,可目前项目里不需要这样,需要统一的(如“0712061546_7199f4.jpg”)这样日期加6位随机的命名规则。于是,就有了如下改动:
首先,找到io.php的SanitizeFileName函数(约在206行~270行之间,我的在266行),原函数为://Doacleanupofthefilenametoavoidpossibleproblems
functionSanitizeFileName($sNewFileName)
{
global$Config;
$sNewFileName=stripslashes($sNewFileName);
//Replacedotsinthenamewithunderscores(onlyonedotcanbethere...securityissue).
if($Config['ForceSingleExtension'])
$sNewFileName=preg_replace('/\\.(?![^.]*$)/','_',$sNewFileName);
//Remove\/|:?*"
$sNewFileName=preg_replace('/\\\\|\\/|\\||\\:|\\?|\\*|"||[[:cntrl:]]/','_',$sNewFileName);
return$sNewFileName;
}
这个函数用来修正文件名的字符,就拿他开刀,改为://Doacleanupofthefilenametoavoidpossibleproblems
functionSanitizeFileName($sNewFileName)
{
global$Config;
$sNewFileName=stripslashes($sNewFileName);
//Replacedotsinthenamewithunderscores(onlyonedotcanbethere...securityissue).
if($Config['ForceSingleExtension'])
$sNewFileName=preg_replace('/\\.(?![^.]*$)/','_',$sNewFileName);
//Remove\/|:?*"
//$sNewFileName=preg_replace('/\\\\|\\/|\\||\\:|\\?|\\*|"||[[:cntrl:]]/','_',$sNewFileName);
//注释上面一行原有的文件名,并在下面自定义文件命名规则
$sExtension=substr($sNewFileName,(strrpos($sNewFileName,'.')+1));
$sNewFileName=my_setfilename().'.'.$sExtension;
//修改结束
return$sNewFileName;
}
这里使用了一个新的命名规则函数“my_setfilename”,内容如下://自定义文件命名规则函数
functionmy_setfilename(){
//生成随机字符串
$string='abcdefghijklmnopgrstuvwxyz0123456789';
$rand='';
for($x=0;$x<6;$x++)
$rand.=substr($string,mt_rand(0,strlen($string)-1),1);
returndate("YmdHis").'_'.$rand;//以“日期_随机字符串”方式返回新文件名
}
补充:按照日期分类文件夹存放文件,我没有用
方法:找到config.php文件,32行的样子://Pathtouserfilesrelativetothedocumentroot.
$Config['UserFilesPath']='/Upload/';
改为://Pathtouserfilesrelativetothedocumentroot.
$Config['UserFilesPath']='/Upload/'.date("Ymd").'/';
//当文件夹不存在的时候貌似会自动创建
本文来自投稿,不代表访得立场,如若转载,请注明出处://view/159.html