fckeditor php上传文件重命名的设置

网络编程 2025-03-24 11:00www.168986.cn编程入门

我使用的文本编辑器是fckeditor的2.6.4版本。在默认情况下,fckeditor上传文件并不会自动重命名,这导致在上传中文文件或名称重复的文件时可能会遇到一些困扰。为了解决这一问题,我经过找到了一个重命名的方法,大家可以看看是否好用。

想要根据日期来组织上传的文件存放的文件夹,我们需要修改editor\editor\filemanager\connectors\php文件夹下的config.php文件。找到如下的内容:

```php

// Path to user files relative to the document root.

$Config['UserFilesPath'] =

```

将其修改为:

```php

// Path to user files relative to the document root.

$Config['UserFilesPath'] = '/uploadfiles/'.date("Ym")."/" ;

```

这样设置后,上传的文件就会按照日期存放在不同的文件夹内。

接下来是重命名的问题,我们需要修改该文件夹下的io.php文件。找到原有的SanitizeFileName函数,并进行如下修改:

```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 ) ;

$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;

}

```

这样修改后,上传的文件就会被自动重命名。新的文件名会包含日期、时间、随机字符串以及原始文件的扩展名,这样既可以避免文件名重复,又可以方便地按照日期找到文件。这样一来,文件管理将变得更加轻松便捷。

上一篇:ASP.NET MVC3网站创建与发布(1) 下一篇:没有了

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by