• FCKeditor 上传图片自动重命名


    FCKeditor 的文件上传默认是不改名的,本地的文件名是什么,上传后保留原来的文件名;如果存在同名文件,则会被自动在文件名后面加 (n) 来标识。

    FCKeditor For ASP.NET 的上传部分被编译到 DLL 文件里面了,所以只能通过修改源代码,再重新编译后方能使用。

    使用:FCKeditor.Net_2.5.zip,asp.net 2.0版

    找到项目中的FileBrowser/FileWorkerBase.cs

    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 + ")." + sExtension;

                        iErrorNumber = 201;
                    }
                    else
                    ...{
                        oFile.SaveAs(sFilePath);
                        break;
                    }
                }
    修改后的代码变成:

    while (true)
                ...{
                    sFileName = DateTime.Now.ToString("yyyymmddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "." + sExtension;//以时间命名文件

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

                    oFile.SaveAs(sFilePath);
                    break;
                }

    详见:

                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 + ")." +
                    
    //        sExtension;

                    
    //    iErrorNumber = 201;
                    
    //}
                    
    //else
                    
    //{
                    
    //    oFile.SaveAs( sFilePath );
                    
    //    break;
                    
    //}

                    sFileName 
    = DateTime.Now.ToString("yyyyMMddhhmmssffff", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "." + sExtension;//以时间命名文件

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

                    oFile.SaveAs(sFilePath);
                    
    break;
                }

    重新生成解决方案。在网站项目中删除旧的FredCK.FCKeditorV2.dll,再添加新的引用,就OK了。

  • 相关阅读:
    201771010135 杨蓉庆《面对对象程序设计(java)》第十五周学习总结
    201771010135 杨蓉庆/张燕/杨玲《面对对象程序设计(java)》第十四周学习总结
    201771010135 杨蓉庆/张燕《面对对象程序设计(java)》第十三周学习总结
    团队作业6—复审与事后分析
    团队作业6——Alpha阶段项目复审
    团队作业6——事后分析
    团队作业5——测试与发布(Alpha版本)
    团队作业4-项目汇总
    团队作业4-Day7
    团队作业4-Day6
  • 原文地址:https://www.cnblogs.com/wangpei/p/1512309.html
Copyright © 2020-2023  润新知