ecshop是一套非常好的網(wǎng)店系統(tǒng),fckeditor也是個不錯的html編輯器,常用于各種cms及商城系統(tǒng)實現(xiàn)在紡編輯html代碼,然后ecshop使用的fckeditor在上傳圖片和其它文件時是沒有按目錄存放的。
我們很多人都習慣上傳的文件按年和月這樣的日期存放這樣不至于上傳文件夾存放的內容太多太雜,影響系統(tǒng)的穩(wěn)定性,同時上傳的文件也沒有進行重命名,當我們上傳中文文件名的文件時有些時候會出錯,下面我們就來實現(xiàn):
一、ecshop的fckeditor上傳文件時按年和日存放,假如我們是2012年3月存放的,系統(tǒng)會自動建一個文件夾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的后臺測試就會發(fā)現(xiàn)我們上傳的圖片按年月分目錄保存并自動重命名了!
經(jīng)測試ecshop V2.7.3 20120411版本還未失效的!
|
新聞熱點
疑難解答
圖片精選