Rename files in the asp version of fckeditor

Source: Internet
Author: User
Tags control characters

Go to editor \ filemanager \ connectors \ asp \ io. asp.
Modify the SanitizeFileName function and add a method to get the extension and rename the file. The detailed code is as follows: Copy codeThe Code is as follows: '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 ,"_")
'Get File Extension
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, limit Rev (filename, ".") + 1, len (filename)-limit Rev (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 is a variable, and fname is a function parameter reference.
Fname = replace (fname ,"-","")
Fname = replace (fname ,"","")
Fname = replace (fname ,":","")
Fname = replace (fname, "PM ","")
Fname = replace (fname, "AM ","")
Fname = replace (fname, "Morning ","")
Fname = replace (fname, "Afternoon ","")
Makefilename = fname
End function

Copy the following code if you are too lazy to modify it:Copy codeThe Code is as follows: <%
'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 \
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, limit Rev (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 ,"_")
'Get File Extension
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, limit Rev (filename, ".") + 1, len (filename)-limit Rev (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 is a variable, and fname is a function parameter reference.
Fname = replace (fname ,"-","")
Fname = replace (fname ,"","")
Fname = replace (fname ,":","")
Fname = replace (fname, "PM ","")
Fname = replace (fname, "AM ","")
Fname = replace (fname, "Morning ","")
Fname = replace (fname, "Afternoon ","")
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 agion too many parent.doc ument. 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
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.