fckeditor asp版本的文件重命名

定位到:editor\filemanager\connectors\asp\io.asp
主要是修改:SanitizeFileName这个函数,并添加取得扩展名和文件重命名的方法,详细代码如下:


代码如下:

' Do a cleanup of the file name to avoid possible problems
function SanitizeFileName( sNewFileName )
Dim oRegex
Dim oExt
Set oRegex = New RegExp
oRegex.Global = True

if ( ConfigForceSingleExtension = True ) then
oRegex.Pattern = "\.(?![^.]*$)"
sNewFileName = oRegex.Replace( sNewFileName, "_" )
'取得文件扩展名
sNewFileName = makefilename(now())"."&GetExtend(sNewFileName)
end if

' remove \ / | : ? * " < > and control characters
oRegex.Pattern = "(\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"
SanitizeFileName = oRegex.Replace( sNewFileName, "_" )

Set oRegex = Nothing
end function

Function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
End Function

function makefilename(fname)
fname = fname '前fname为变量,后fname为函数参数引用
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
makefilename = fname
end function

懒得改的话就直接拷贝下面的代码:


代码如下:

<%
' FCKeditor - The text editor for Internet - http://www.fckeditor.net
' Copyright (C) 2003-2009 Frederico Caldeira Knabben
'
' == BEGIN LICENSE ==
'
' Licensed under the terms of any of the following licenses at your
' choice:
'
' - GNU General Public License Version 2 or later (the "GPL")
' http://www.gnu.org/licenses/gpl.html
'
' - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
' http://www.gnu.org/licenses/lgpl.html
'
' - Mozilla Public License Version 1.1 or later (the "MPL")
' http://www.mozilla.org/MPL/MPL-1.1.html
'
' == END LICENSE ==
'
' This file include IO specific functions used by the ASP Connector.
%>
<%
function CombinePaths( sBasePath, sFolder)
sFolder = replace(sFolder, "\", "/")
CombinePaths = RemoveFromEnd( sBasePath, "/" ) & "/" & RemoveFromStart( sFolder, "/" )
end function

function CombineLocalPaths( sBasePath, sFolder)
sFolder = replace(sFolder, "/", "\")
' The RemoveFrom* functions use RegExp, so we must escape the \
CombineLocalPaths = RemoveFromEnd( sBasePath, "\\" ) & "\" & RemoveFromStart( sFolder, "\\" )
end function

Function GetResourceTypePath( resourceType, sCommand )
if ( sCommand = "QuickUpload") then
GetResourceTypePath = ConfigQuickUploadPath.Item( resourceType )
else
GetResourceTypePath = ConfigFileTypesPath.Item( resourceType )
end if
end Function

Function GetResourceTypeDirectory( resourceType, sCommand )
if ( sCommand = "QuickUpload") then

if ( ConfigQuickUploadAbsolutePath.Item( resourceType ) <> "" ) then
GetResourceTypeDirectory = ConfigQuickUploadAbsolutePath.Item( resourceType )
else
' Map the "UserFiles" path to a local directory.
GetResourceTypeDirectory = Server.MapPath( ConfigQuickUploadPath.Item( resourceType ) )
end if
else
if ( ConfigFileTypesAbsolutePath.Item( resourceType ) <> "" ) then
GetResourceTypeDirectory = ConfigFileTypesAbsolutePath.Item( resourceType )
else
' Map the "UserFiles" path to a local directory.
GetResourceTypeDirectory = Server.MapPath( ConfigFileTypesPath.Item( resourceType ) )
end if
end if
end Function

Function GetUrlFromPath( resourceType, folderPath, sCommand )
GetUrlFromPath = CombinePaths( GetResourceTypePath( resourceType, sCommand ), folderPath )
End Function

Function RemoveExtension( fileName )
RemoveExtension = Left( fileName, InStrRev( fileName, "." ) - 1 )
End Function

Function ServerMapFolder( resourceType, folderPath, sCommand )
Dim sResourceTypePath
' Get the resource type directory.
sResourceTypePath = GetResourceTypeDirectory( resourceType, sCommand )

' Ensure that the directory exists.
CreateServerFolder sResourceTypePath

' Return the resource type directory combined with the required path.
ServerMapFolder = CombineLocalPaths( sResourceTypePath, folderPath )
End Function

Sub CreateServerFolder( folderPath )
Dim oFSO
Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" )

Dim sParent
sParent = oFSO.GetParentFolderName( folderPath )

' If folderPath is a network path (\\server\folder\) then sParent is an empty string.
' Get out.
if (sParent = "") then exit sub

' Check if the parent exists, or create it.
If ( NOT oFSO.FolderExists( sParent ) ) Then CreateServerFolder( sParent )

If ( oFSO.FolderExists( folderPath ) = False ) Then
On Error resume next
oFSO.CreateFolder( folderPath )

if err.number<>0 then
dim sErrorNumber
Dim iErrNumber, sErrDescription
iErrNumber = err.number
sErrDescription = err.Description

On Error Goto 0

Select Case iErrNumber
Case 52
sErrorNumber = "102" ' Invalid Folder Name.
Case 70
sErrorNumber = "103" ' Security Error.
Case 76
sErrorNumber = "102" ' Path too long.
Case Else
sErrorNumber = "110"
End Select

SendError sErrorNumber, "CreateServerFolder(" & folderPath & ") : " & sErrDescription
end if

End If

Set oFSO = Nothing
End Sub

Function IsAllowedExt( extension, resourceType )
Dim oRE
Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global = True

Dim sAllowed, sDenied
sAllowed = ConfigAllowedExtensions.Item( resourceType )
sDenied = ConfigDeniedExtensions.Item( resourceType )

IsAllowedExt = True

If sDenied <> "" Then
oRE.Pattern = sDenied
IsAllowedExt = Not oRE.Test( extension )
End If

If IsAllowedExt And sAllowed <> "" Then
oRE.Pattern = sAllowed
IsAllowedExt = oRE.Test( extension )
End If

Set oRE = Nothing
End Function

Function IsAllowedType( resourceType )
Dim oRE
Set oRE = New RegExp
oRE.IgnoreCase = False
oRE.Global = True
oRE.Pattern = "^(" & ConfigAllowedTypes & ")$"

IsAllowedType = oRE.Test( resourceType )

Set oRE = Nothing
End Function

Function IsAllowedCommand( sCommand )
Dim oRE
Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global = True
oRE.Pattern = "^(" & ConfigAllowedCommands & ")$"

IsAllowedCommand = oRE.Test( sCommand )

Set oRE = Nothing
End Function

function GetCurrentFolder()
dim sCurrentFolder
dim oRegex

sCurrentFolder = Request.QueryString("CurrentFolder")
If ( sCurrentFolder = "" ) Then sCurrentFolder = "/"

' Check the current folder syntax (must begin and start with a slash).
If ( Right( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = sCurrentFolder & "/"
If ( Left( sCurrentFolder, 1 ) <> "/" ) Then sCurrentFolder = "/" & sCurrentFolder

' Check for invalid folder paths (..)
If ( InStr( 1, sCurrentFolder, ".." ) <> 0 OR InStr( 1, sCurrentFolder, "\" ) <> 0) Then
SendError 102, ""
End If

Set oRegex = New RegExp
oRegex.Global = True
oRegex.Pattern = "(/\.)|(//)|([\\:\*\?\""\<\>\|]|[\u0000-\u001F]|\u007F)"

if (oRegex.Test(sCurrentFolder)) Then
SendError 102, ""
End If

GetCurrentFolder = sCurrentFolder
end function

' Do a cleanup of the folder name to avoid possible problems
function SanitizeFolderName( sNewFolderName )
Dim oRegex
Set oRegex = New RegExp
oRegex.Global = True

' remove . \ / | : ? * " < > and control characters
oRegex.Pattern = "(\.|\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"
SanitizeFolderName = oRegex.Replace( sNewFolderName, "_" )

Set oRegex = Nothing
end function

' Do a cleanup of the file name to avoid possible problems
function SanitizeFileName( sNewFileName )
Dim oRegex
Dim oExt
Set oRegex = New RegExp
oRegex.Global = True

if ( ConfigForceSingleExtension = True ) then
oRegex.Pattern = "\.(?![^.]*$)"
sNewFileName = oRegex.Replace( sNewFileName, "_" )
'取得文件扩展名
sNewFileName = makefilename(now())&"."&GetExtend(sNewFileName)
end if

' remove \ / | : ? * " < > and control characters
oRegex.Pattern = "(\\|\/|\||:|\?|\*|""|\<|\>|[\u0000-\u001F]|\u007F)"
SanitizeFileName = oRegex.Replace( sNewFileName, "_" )

Set oRegex = Nothing
end function

Function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
End Function

function makefilename(fname)
fname = fname '前fname为变量,后fname为函数参数引用
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
makefilename = fname
end function

' This is the function that sends the results of the uploading process.
Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )
Response.Clear
Response.Write "<script type=""text/javascript"">"
' Minified version of the document.domain automatic fix script (#1919).
' The original script can be found at _dev/domain_fix_template.js
Response.Write "(function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();"

Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "\""" ) & """,""" & Replace( fileName, """", "\""" ) & """,""" & Replace( customMsg , """", "\""" ) & """) ;"
Response.Write "</script>"
Response.End
End Sub
%>

(0)

相关推荐

  • fckeditor asp版本的文件重命名

    定位到:editor\filemanager\connectors\asp\io.asp 主要是修改:SanitizeFileName这个函数,并添加取得扩展名和文件重命名的方法,详细代码如下: 复制代码 代码如下: ' Do a cleanup of the file name to avoid possible problems function SanitizeFileName( sNewFileName ) Dim oRegex Dim oExt Set oRegex = New Reg

  • fckeditor php上传文件重命名的设置

    这里经过摸索:找到了一个重命名的方法,大家看看好不好使. 首先:我希望上传的文件根据日期来组织文件夹 请修改editor\editor\filemanager\connectors\php文件夹下的:config.php文件 找到如下的内容: // Path to user files relative to the document root. $Config['UserFilesPath'] = 修改为: // Path to user files relative to the docum

  • aspupload文件重命名及上传进度条的解决方法附代码第1/2页

    发现还没有aspupload这个组件的,这两样功能的解决方案,现把我的改进方案写在这里!谢谢  关于aspupload上传组件,文件重命名,进度条的问题解决方案!  共用到4个文件,分别是1.asp,2.asp,bar.asp,framebar.asp  运行第一个文件:1.asp,执行上传操作!  复制代码 代码如下: <% '''进度条 dim SPid,PID,barref Set UploadProgress = Server.CreateObject("Persits.Uploa

  • Python和perl实现批量对目录下电子书文件重命名的代码分享

    经常会遇到下载的文件或电子书,名字中间都包含了一些网址信息,实际使用中由于名字太长不方便,下面的脚本使用正则表达式来对目录下的所有文件重命名: 例如: 修改前:[我们]Mac OS X for Unix Geeks[www.jb51.net].mobi 修改后:Mac OS X for Unix Geeks.mobi python代码如下: 复制代码 代码如下: import os import re def rename_dir(dir,regex,f):   if not os.path.i

  • java文件重命名(文件批量重命名)实例程序代码分享

    首先,查到java里文件重命名的方法为:renameTo(); 我将180张图片放在d:\\backup下,用下面的程序进行重命名: 复制代码 代码如下: public void reName(){        String dir = "D:\\backup\\";        File file = new File(dir);        String fileName[] = file.list();        int number = fileName.length

  • php 随机数的产生、页面跳转、件读写、文件重命名、switch语句

    复制代码 代码如下: <?php num = rand(1,5); witch($num){ case 1: $fp1=fopen("f1.dat",'r'); $oname = fgets($fp1); $nname = date("YmdHis"); rename($oname,$nname); fclose($fp1); unlink("f1.dat"); $fp1=fopen("f1.dat",'w'); fwr

  • Zend Framework上传文件重命名的实现方法

    本文实例讲述了Zend Framework上传文件重命名的实现方法.分享给大家供大家参考,具体如下: 1. Zend Framework文件上传重命名 //实例化文件上专类 $fName=$this->_request->getPost('fName'); $adapter = new Zend_File_Transfer_Adapter_Http(); //存放上传文件的文件夹 $adapter->setDestination('/opt/lampp/htdocs/blog/uploa

  • java实现文件重命名的方法

    本文实例讲述了java实现文件重命名的方法.分享给大家供大家参考.具体如下: 下载的电影总是有一些存在网站名称等没用的信息 作为一个强迫症患者 一定要删除他们 package sys.file; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.io.*; public class ZReName { public static void main(Str

  • python实现批量文件重命名

    本文实例为大家分享了python批量文件重命名的具体代码,供大家参考,具体内容如下 问题描述 最近遇到朋友求助,如何将大量文件名前面的某些字符删除. 即将图中文件前的编号删除. Python实现 用到了python中的os模块,os模块中的rename方法可以实现对文件的重命名 import os #path为批量文件的文件夹的路径 path = 'd:\\renamefolder' #文件夹中所有文件的文件名 file_names = os.listdir(path) #外循环遍历所有文件名,

  • java实现文件重命名功能

    本文实例为大家分享了java实现文件重命名的具体代码,供大家参考,具体内容如下 使用java i/o流读取文件夹中的所有的文件,并实现按照指定的规则进行重命名 1.直接建一个util类,来进行创建两个重命名的方法: package reName; import java.io.File; public class util { /** * 用于将文件名按照指定数字往后排 * @param startNum * @param url */ public static void sort(int s

随机推荐