fckeditor php上傳文件重命名的設(shè)置
更新時(shí)間:2009年04月17日 21:32:26 作者:
我使用的fckeditor版本是fckeditor2.6.4.
fckeditor默認(rèn)上傳文件不沒有重命名的,這樣的話就很麻煩,有時(shí)上傳中文的文件或者名稱重復(fù)的文件就很惱火。
這里經(jīng)過摸索:找到了一個(gè)重命名的方法,大家看看好不好使。
首先:我希望上傳的文件根據(jù)日期來組織文件夾
請(qǐng)修改editor\editor\filemanager\connectors\php文件夾下的:config.php文件
找到如下的內(nèi)容:
// Path to user files relative to the document root.
$Config['UserFilesPath'] =
修改為:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = '/uploadfiles/'.date("Ym")."/" ;
這樣上傳的文件就按照日期存放了。
其次:重命名
請(qǐng)修改該文件夾下的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( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>/', '_', $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 ) ;
$sExtension = substr( $sNewFileName, ( strrpos($sNewFileName, '.') + 1 ) ) ;
$sNewFileName = my_setfilename().'.'.$sExtension;
return $sNewFileName ;
}
function my_setfilename(){
$gettime = explode(' ',microtime());
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
return date("ymdHis").substr($gettime[0],2,6).$rand;
}
這樣上傳的文件就可以實(shí)現(xiàn)重命名了。
首先:我希望上傳的文件根據(jù)日期來組織文件夾
請(qǐng)修改editor\editor\filemanager\connectors\php文件夾下的:config.php文件
找到如下的內(nèi)容:
// Path to user files relative to the document root.
$Config['UserFilesPath'] =
修改為:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = '/uploadfiles/'.date("Ym")."/" ;
這樣上傳的文件就按照日期存放了。
其次:重命名
請(qǐng)修改該文件夾下的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( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>/', '_', $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 ) ;
$sExtension = substr( $sNewFileName, ( strrpos($sNewFileName, '.') + 1 ) ) ;
$sNewFileName = my_setfilename().'.'.$sExtension;
return $sNewFileName ;
}
function my_setfilename(){
$gettime = explode(' ',microtime());
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
return date("ymdHis").substr($gettime[0],2,6).$rand;
}
這樣上傳的文件就可以實(shí)現(xiàn)重命名了。
您可能感興趣的文章:
- PHP自動(dòng)重命名文件實(shí)現(xiàn)方法
- php 隨機(jī)數(shù)的產(chǎn)生、頁(yè)面跳轉(zhuǎn)、件讀寫、文件重命名、switch語(yǔ)句
- 6種php上傳圖片重命名的方法實(shí)例
- 基于php上傳圖片重命名的6種解決方法的詳細(xì)介紹
- PHP批量修改文件名稱的方法分析
- php實(shí)現(xiàn)批量修改文件名稱的方法
- PHP實(shí)現(xiàn)批量修改文件后綴名的方法
- php實(shí)現(xiàn)文件編碼批量轉(zhuǎn)換
- php中批量修改文件后綴名的函數(shù)代碼
- php中批量替換文件名的實(shí)現(xiàn)代碼
- PHP實(shí)現(xiàn)批量重命名某個(gè)文件夾下所有文件的方法
相關(guān)文章
ckeditor syntaxhighlighter代碼高亮插件,完美修復(fù)
昨天匆忙發(fā)了個(gè)更新版,今天去找ckeditor的api文檔看了很久,終于找到解決辦法了2011-08-08
FCKeditor 2.6.6在ASP中的安裝及配置方法分享
FCKeditor目前的最新版本是2.6.6,在網(wǎng)上搜索此版本的配置方法,發(fā)現(xiàn)很少有asp的配置方法,以下就把自己的一些配置經(jīng)驗(yàn)分享給有需要的你。2012-03-03
新浪博客在線編輯器傻瓜調(diào)用版(2007.11.1第四次修正)提供下載了
新浪博客在線編輯器傻瓜調(diào)用版(2007.11.1第四次修正)提供下載了...2007-11-11
配置fckeditor 實(shí)現(xiàn)圖片的上傳
配置fckeditor 實(shí)現(xiàn)圖片的上傳2009-11-11
關(guān)于jsp版ueditor1.2.5的部分問題解決(上傳圖片失敗)
這篇文章主要介紹大家在使用jsp版ueditor1.2.5的碰到的一些問題解決方法,需要的朋友可以參考下2013-06-06
eWebEditor 輯器按鈕失效 IE8下eWebEditor編輯器無法使用的解決方法
最近我把IE瀏覽器更新到了IE8.0,在用eWebEditor在線HTML文本編輯器的時(shí)候點(diǎn)擊eWebEditor上的所有編輯按鈕都沒用,只看到瀏覽器狀態(tài)欄左下角顯示網(wǎng)頁(yè)上有錯(cuò)誤,于是上網(wǎng)查了一下。終于找到解決的方法,測(cè)試后正常。2009-06-06

