FCKeditor V2.x上传文件自动重命名
大意是如果存在同名文件则在文件名后加入 (n) 来标识,否则以原文件名保存。把它改成不论有没有同名文件,都重新生成一个新的文件名。修改后的代码变成:
while ( true )
......{
// Rebuild file name.
sFileName = DateTime.Now.ToString().Replace("-","").Replace(" ","").Replace(":","")+System.IO.Path.GetExtension(oFile.FileName);
string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;
![]()
oFile.SaveAs( sFilePath ) ;
sFileUrl = this.UserFilesPath + sFileName ;
break ;
}
DataTime.Now.ToString()是获取当前时间并转换为字符串,得到的结果以 YYYY-MM-DD HH:MM:SS 的形式出现,用 Replace 把其中的分隔符及空格替换掉;再加上原文件的扩展名,“快速上传”修改完成。上传后的文件以 2005126152012.jpg 的命名方式存放到服务器上。
再打开 FileBrowserConnector.cs 文件,找到 Command Handlers 区中的 FileUpload 函数段,同样是修改 while 语句中的内容:
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 )
......{
// Rebuild file name.
sFileName = DateTime.Now.ToString().Replace("-","").Replace(" ","").Replace(":","")+System.IO.Path.GetExtension(oFile.FileName);
string sFilePath = System.IO.Path.Combine( sServerDir, sFileName ) ;
oFile.SaveAs( sFilePath ) ;
break ;
}
因为不再使用 iCounter 变量,所以一并去除。保存文件,重新生成解决方案;打开网站项目,在引用中删除原来的 FredCK.FCKeditorV2,再把刚才生成的 FredCK.FCKeditorV2.dll 文件复制到网站 bin 目录下,重新添加引用、生成,就大功告成了。
0
相关文章
