一、ecshop的fckeditor上传文件时按年和日存放,假如我们是2012年3月存放的,系统会自动建一个文件夹201207,方法
打开includes/fckeditor/editor/filemanager/connectors/php/config.php,找到:
修改前的代码:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = $root_path . IMAGE_DIR . '/upload/';
// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$Config['UserFilesAbsolutePath'] = ROOT_PATH . IMAGE_DIR . '/upload/' ;
修改后的代码:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = $root_path . IMAGE_DIR . '/upload/'.date('Ym').'/';
// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$Config['UserFilesAbsolutePath'] = ROOT_PATH . IMAGE_DIR . '/upload/'.date('Ym').'/';
然后保存,非常简单,仅是在这两行后面增加了 .date('Ym').'/'
二、ecshop的fckeditor上传文件时自动重命名,方法:
找到includes/fckeditor/editor/filemanager/connectors/php/io.php,找到
修改前的代码:
// Do a cleanup of the file name to avoid possible problems
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 ) ;
return $sNewFileName ;
}
修改后的代码:
// Do a cleanup of the file name to avoid possible problems
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('YmdHis').rand(0,999).'.'.$sExtension;
return $sNewFileName ;
}
就是把
$sNewFileName = preg_replace( '/\\|\/|\||\:|\?|\*|"|<|>|[[:cntrl:]]/', '_', $sNewFileName ) ; 注释掉,新增加
$sExtension = substr( $sNewFileName, (strrpos($sNewFileName,'.') + 1 ) ) ;
$sNewFileName = date('YmdHis').rand(0,999).'.'.$sExtension;
保存后,在ecshop的后台测试就会发现我们上传的图片按年月分目录保存并自动重命名了!
经测试ecshop V2.7.3 20120411版本还未失效的!