FCKeditor ASP version of File Rename _ Web page Editor

Source: Internet
Author: User
Tags control characters
Navigate to: Editor\filemanager\connectors\asp\io.asp
Mainly modify: Sanitizefilename This function, and add a method to get extension and file renaming, the detailed code is as follows:
Copy Code code 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 name 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,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 ' before fname as variable, after fname for function parameter reference
fname = replace (fname, "-", "")
fname = replace (fname, "", "")
fname = replace (fname, ":", "")
fname = replace (fname, "PM", "")
fname = replace (fname, "AM", "")
fname = replace (fname, "a.m.", "")
fname = replace (fname, "PM", "")
Makefilename = fname
End Function

If you don't bother to change, copy the following code directly:
Copy Code code 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 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 and 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 directory exists.
Createserverfolder Sresourcetypepath

' Return to 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 a empty string.
' Get out.
if (sparent = "") Then Exit Sub

' Check if ' 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 = "The" "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 name 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,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 ' before fname as variable, after fname for function parameter reference
fname = replace (fname, "-", "")
fname = replace (fname, "", "")
fname = replace (fname, ":", "")
fname = replace (fname, "PM", "")
fname = replace (fname, "AM", "")
fname = replace (fname, "a.m.", "")
fname = replace (fname, "PM", "")
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
%>
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.