Oct
4
fckeditor2.6.4上传文件按日期存放及重命名方法
搜索
我已经获得阿里云幸运券,准备分享给您。请点击获取
fckeditor2.6.4上传文件按日期存放及重命名方法
how-fckeditor-change-uploadfile-path-and-filename by itlife365.com
原因备注:现在的fckeditor 都已经到版本4了,因为之前使用的是2.6.4 所以目前只能基于这个版本进行修改。
1、实现 fckeditor 按日期分目录的形式存放上传的文件,比如今天是 2020年10月4日,那么今天上传的文件都放在这个目录里面去,明天上传的则自动创建并放在类似 2020-10-05 这样的目录里面去。
(1)找到 editor\editor\filemanager\connectors\php\ 文件夹下的 config.php 文件(/editor/fckeditor/editor/filemanager/connectors/php)
(2)找到如下配置变量
PHP代码
- $Config['UserFilesPath'] = '/uploadfiles/';
将其值修改为:
PHP代码
- $Config['UserFilesPath'] = '/uploadfiles/'.date('Ymd').'/'; //根据自己的实际情况
这样上传的文件就按照日期存放了。
---************me_begin
我的配置如下:【我这边是配置 $Config['UserFilesPath'] = '/attachment/' ; 】
之前的图片配置是在如下,格式,为保持兼容,设置为一样的。配置为 /blog/attachment 。
[root@izwz9h blog]# cd attachment
[root@izwz9h attachment]# ls
201011 201202 201210 201305 201311 201406 201501 201512 201611 201707 201806 201902 202010
201012 201203 201211 201306 201401 201407 201503 201601 201612 201708 201809 201906 index.php
201106 201206 201212 201307 201402 201408 201506 201603 201701 201712 201811 201911
201107 201207 201301 201309 201403 201410 201509 201604 201705 201804 201812 202001
201108 201209 201302 201310 201404 201412 201511 201610 201706 201805 201901 202002
[root@izwz9h attachment]# pwd
/var/www/itlife365.com/web/blog/attachment
[root@izwz9h attachment]# ll 202010/
total 64
-rwxr-xr-x 1 web3 client2 25724 Oct 2 17:00 1601629254_74608341.jpg
-rwxr-xr-x 1 web3 client2 34115 Oct 4 09:48 1601776095_533634af.jpg
[root@izwz9h attachment]#
新的配置:
fckeditor 下会有3个子文件夹,刚好可以与原来区分开来
[root@izwz9h attachment]# ls
file flash image
[root@izwz9h attachment]#
---************me_end
2、重命名 fckeditor 上传的文件的方法
FCKeditor 的文件上传默认是不改名的,本地的文件名是什么,上传后保留原来的文件名;如果存在同名文件,则会被自动在文件名后面加 (n) 来标识。
(1)找到 editor\editor\filemanager\connectors\php\io.php 文件:
(2)找到如下内容:
PHP代码
- ......
- function SanitizeFileName( $sNewFileName ){
- global $Config ;
- $sNewFileName = stripslashes( $sNewFileName ) ;
- if ( $Config['ForceSingleExtension'] )
- $sNewFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sNewFileName ) ;
- $sNewFileName = preg_replace( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>/', '_', $sNewFileName );
- return $sNewFileName ;
- }
- ......
修改为如下语句:
PHP代码
- function SanitizeFileName( $sNewFileName ){
- global $Config ;
- $sNewFileName = stripslashes( $sNewFileName ) ;
- if ( $Config['ForceSingleExtension'] )
- $sNewFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sNewFileName ) ;
- //获得扩展名
- $sExtension = substr( $sNewFileName, ( strrpos($sNewFileName, '.') + 1 ) ) ;
- $sExtension = strtolower( $sExtension ) ;
- $sNewFileName = date("YmdHis").'.'.$sExtension;
- return $sNewFileName ;
- }
现在上传的文件就会自动被重命名了。
其他:自定义 FCKeditor 的 BasePath
当然,
自定义 FCKeditor 的 BasePath:BasePath 即FCKeditor在网站中的相对路径,默认值是 /fckeditor/,最好在Web.config appSettings中对其进行配置:
<add key="FCKeditor:BasePath" value="/FCKeditor_2.6.3/"/>
这样做有诸多优点:how-fckeditor-change-uploadfile-path-and-filename by itlife365.com
开发环境与生产环境不同,开发环境一般是http://localhost/xxx.com/这种情况下FCKeditor就得放在一个虚拟目录http://localhost/fckeditor/中,若涉及多个网站的开发,而各网站的FCKeditor有差别时,这样显然不是最优;
而且因为物理目录结构与逻辑目录结构不同,也会有发生错误的隐患;
而如果采用Web.config的配置,就可以在开发环境采用不同的配置,FCKeditor的物理路径与生产环境保持一致;
当升级FCKeditor时,只需要将新版本的FCKeditor放在相应版本号的目录里,修改一下配置即可。这样可以解决因为静态资源的客户端缓存问题,不同用户出现不同的错误的问题;
可以直观地看到自己的FCKeditor的版本号。
如果找到变量BasePath的配置。目前我这个因为是集成就的自己查找关键字BasePath。
我的是在文件 blog/editor/fckeditor/editordef.php 中
oFCKeditor.BasePath = '/blog/editor/fckeditor/' ;
上传图片带水印
在FileUpload方法中找到oFile.SaveAs( sFilePath );语句。在其后加入 xxx 略
how-fckeditor-change-uploadfile-path-and-filename by itlife365.com end