当前位置: 代码迷 >> ASP.NET >> ckfinder 如何给下传的文件改名
  详细解决方案

ckfinder 如何给下传的文件改名

热度:9430   发布时间:2013-02-25 00:00:00.0
ckfinder 怎么给上传的文件改名
ckfinder 怎么给上传的文件改名 .

------解决方案--------------------------------------------------------
C# code
while ( true )                        {                            sFilePath = System.IO.Path.Combine( sServerDir, sFileName );                            if ( System.IO.File.Exists( sFilePath ) )                            {                                iCounter++;                                sFileName =                                    sFileNameNoExt +                                    "(" + iCounter + ")" +                                    System.IO.Path.GetExtension( oFile.FileName );                                iErrorNumber = Errors.UploadedFileRenamed;                            }                            else                            {                                oFile.SaveAs( sFilePath );                                if ( Config.Current.SecureImageUploads && ImageTools.IsImageExtension( sExtension ) && !ImageTools.ValidateImage( sFilePath ) )                                {                                    System.IO.File.Delete( sFilePath );                                    ConnectorException.Throw( Errors.UploadedCorrupt );                                }                                Settings.Images imagesSettings = Config.Current.Images;                                if ( imagesSettings.MaxHeight > 0 && imagesSettings.MaxWidth > 0 )                                {                                    ImageTools.ResizeImage( sFilePath, sFilePath, imagesSettings.MaxWidth, imagesSettings.MaxHeight, true, imagesSettings.Quality );                                    if ( Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 )                                    {                                        long fileSize = new System.IO.FileInfo( sFilePath ).Length;                                        if ( fileSize > this.CurrentFolder.ResourceTypeInfo.MaxSize )                                        {                                            System.IO.File.Delete( sFilePath );                                            ConnectorException.Throw( Errors.UploadedTooBig );                                        }                                    }                                }                                break;                            }                        }
------解决方案--------------------------------------------------------
修改 ckfinder\_source\Connector\CommandHandlers\FileUploadCommandHandler.cs 文件
C# code
string sExtension = System.IO.Path.GetExtension( oFile.FileName );sExtension = sExtension.TrimStart( '.' );sFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + sExtension;