FCKeditor 默认上传是不改名的,所以,对于一些不支持中文名的服务器,当本地上传了中文名的文件后就无法访问了。
仍旧用日期加时间的命名方式来保存至服务器。


整个过程就是修改FCK的.net 源码,编译生成 FredCK.FCKeditorV2.dll 放置 bin 目录即可。


共修改三个地方:
Uploader.cs(快速上传,文件重命名)
FileBrowserConnector.cs(按目录上传,文件重命名)
FileWorkerBase.cs(按年月分目录存放文件)


  用 VS.NET 打开 FredCK.FCKeditorV2.csproj,打开 Uploader.cs 文件,找到47行


int iCounter = 0 ;

   while ( true )

   {

   string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;

   if ( System.IO.File.Exists( sFilePath ) )

   {

   iCounter++ ;

   sFileName =

   System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +

   "(" + iCounter + ")" +

   System.IO.Path.GetExtension( oFile.FileName ) ;  

   iErrorNumber = 201 ;

   }

   else

   {

   oFile.SaveAs( sFilePath ) ;  

   sFileUrl = this.UserFilesPath + sFileName ;

   break ;

   }

   }  

  这部分代码表示,上传文件名按原文件名来命名,如有同名则加入 (n) 来标识。

将之修改成   

  while ( true )

   {

   // 重命名文件

     sFileName = "Hztt_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff").Replace(" ", "_").Replace(":", "-") + System.IO.Path.GetExtension(oFile.FileName);

   string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;

   oFile.SaveAs( sFilePath ) ;

   // 按年月分目录输出

     sFileUrl = this.UserFilesPath + DateTime.Now.ToString("yyyy-MM") + "/" + sFileName;

   break ;

   }

  DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")是获取当前时间并转换为格式化的字符串,得到的结果以 2007-07-01 16:05:09 123 的形式出现。上传后的文件以 Hztt_2007-07-01_16-05-09_123.gif 的命名方式存放到服务器上。

  再打开 FileBrowserConnector.cs 文件,找到 Command Handlers 区中的 FileUpload 函数段,修改215行   

  int iCounter = 0 ;  

   while ( true )

   {

   string sFilePath = System.IO.Path.Combine( sServerDir, sFileName ) ;  

   if ( System.IO.File.Exists( sFilePath ) )

   {

   iCounter++ ;

   sFileName =

   System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +

   "(" + iCounter + ")" +

   System.IO.Path.GetExtension( oFile.FileName ) ;  

   sErrorNumber = "201" ;

   }

   else

   {

   oFile.SaveAs( sFilePath ) ;

   break ;

   }

   }

修改成:

                while (true)
                {

                    // 重命名文件

                    sFileName = "Hztt_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff").Replace(" ", "_").Replace(":", "-") + System.IO.Path.GetExtension(oFile.FileName);

                    string sFilePath = System.IO.Path.Combine(sServerDir, sFileName);

                    oFile.SaveAs(sFilePath);

                    break;

                } 

 

上传后的文件同样以 Hztt_2007-07-01_16-05-09_123 .gif 的命名方式存放到服务器上相应的自定义目录中(自定义目录如:file image flash)。

 



  按年月分目录存放文件
打开 FileBrowserConnector.cs 文件,修改 74 行  
 

protected string UserFilesDirectory
        {
            get   
            {
                if ( sUserFilesDirectory == null )
                {
                    // Get the local (server) directory path translation.
                    sUserFilesDirectory = Server.MapPath( this.UserFilesPath ) ;
                }
                return sUserFilesDirectory ;
            }
        }

 

函数的作用就是保存图片的路径,修改成:

        protected string UserFilesDirectory
        {
            get
            {
                if (sUserFilesDirectory == null)
                {
                    string UserPath = Server.MapPath(this.UserFilesPath + DateTime.Now.ToString("yyyy-MM"));

                    if (!System.IO.Directory.Exists(UserPath)) //创建相应的文件夹
                    {
                        System.IO.Directory.CreateDirectory(UserPath);
                    }
                    // Get the local (server) directory path translation.
                    sUserFilesDirectory = UserPath;
                }
                if (!sUserFilesDirectory.EndsWith("/"))
                    sUserFilesDirectory += "/";
                return sUserFilesDirectory;
            }
        }

 

保存修改好的三个CS文件,重新生成解决方案,将\bin\Debug目录下的 FredCK.FCKeditorV2.dll 覆盖掉原来的即可。


点击这里下载相关的文件

upload/1/2007-7-1_18-1-13.rar

压缩包中包含:

其中bin 目录中是已经生成好的  FredCK.FCKeditorV2.dll 文件

backup 目录中是 FCK 官方的 FCKeditor.Net_2.2 源码,

其余则是修改好的源码,可以直接在此基础上再次修改。