Ecshop后台fckeditor上传图片路径修改和重命名上传图片
更新时间:2014-11-19 点击量:1649
ecshop上传的图片都是放在images/upload/Image/下面的,图片多了就不爽了哦。ecshop后台fckeditor上传图片路径修改和重命名上传图片
看了网上很多修改的地方,自己也测试了好几次,现在终于可以了。
Fckeditor上传图片路径修改后的路径是: 已年月日时分秒来区分
images/upload/Image/201303/05143045-6546.jpg
images/upload/Image/年月/日时分秒-四位随机数.上传图片后缀名
我只修改了Image的路径,File、Flash、Media可自己参考修改。
一、修改ecshop fckeditor 图片上传路径只有一点改动:
找到includes/fckeditor/editor/filemanager/connectors/php/config.php
$Config['FileTypesPath']['Image'] = $Config['UserFilesPath'] . 'Image/' ;
$Config['FileTypesAbsolutePath']['Image']= ($Config['UserFilesAbsolutePath'] == '') ? '' : $Config['UserFilesAbsolutePath'].'Image/' ;
改为:
$Config['FileTypesPath']['Image'] = $Config['UserFilesPath'] . 'Image/'. date('Ym',time()+3600*8).'/' ;
$Config['FileTypesAbsolutePath']['Image']= ($Config['UserFilesAbsolutePath'] == '') ? '' : $Config['UserFilesAbsolutePath'].'Image/'. date('Ym',time()+3600*8).'/' ;
就是在后面加了date函数,因为我这里用的UTC时区,所以加了8小时。
二、修改Ecshop fckeditor 上传图片的名字,重命名上传的图片的名字:
找到includes/fckeditor/editor/filemanager/connectors/php/io.php
找到SanitizeFileName函数,
//$sNewFileName = preg_replace( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/', '_', $sNewFileName ) ;
把这一行注释掉,替换为:
$sExtension = substr( $sNewFileName, (strrpos($sNewFileName,'.') + 1 ) ) ; //获取扩展名
$sNewFileName = date('dHis-',time()+3600*8).rand(0,9999).'.'.$sExtension;
替换之后的SanitizeFileName函数如下:
function SanitizeFileName( $sNewFileName )
{
global $Config ;
$sNewFileName = stripslashes( $sNewFileName ) ;
// Replace dots in the name with underscores (only one dot can be there... security issue).
if ( $Config['ForceSingleExtension'] )
$sNewFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sNewFileName ) ;
// Remove \ / | : ? * " < >
//$sNewFileName = preg_replace( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/', '_', $sNewFileName ) ;
$sExtension = substr( $sNewFileName, (strrpos($sNewFileName,'.') + 1 ) ) ;
$sNewFileName = date('dHis-',time()+3600*8).rand(0,9999).'.'.$sExtension; //20130305
return $sNewFileName ;
}
如果文章对您有帮助,就打赏一个吧
«上一篇:让ecshop商品属性显示单选按钮与下拉列表共同展示 下一篇:如何修改ecshop后台重新登陆或超时退出问题»