欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

fckeditor asp版本的文件重命名

程序员文章站 2022-03-07 08:54:11
定位到:editor\filemanager\connectors\asp\io.asp 主要是修改:sanitizefilename这个函数,并添加取得扩展名和文件重命名...
定位到: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
%>