麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > ASP > 正文

網(wǎng)頁編輯器fckeditor asp版本的文件重命名

2024-07-21 02:53:34
字體:
供稿:網(wǎng)友
最近不得不研究FCKEDITOR,而且是ASP版本。對其文件上傳后的重命名,很郁悶。下面記錄我修改的過程,部分函數(shù)來自網(wǎng)絡(luò)。
 
定位到:editor/filemanager/connectors/asp/io.asp 
主要是修改:SanitizeFileName這個函數(shù),并添加取得擴展名和文件重命名的方法,詳細(xì)代碼如下:
復(fù)制代碼代碼如下:

' 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為函數(shù)參數(shù)引用 
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 

懶得改的話就直接拷貝下面的代碼: 
復(fù)制代碼代碼如下:

<% 
' 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為函數(shù)參數(shù)引用 
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 
%> 


注:相關(guān)教程知識閱讀請移步到編輯器頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲精品午夜国产va久久成人 | 国产成人自拍小视频 | 电影91| 久久成人国产精品入口 | 成年毛片 | 狠狠操视频网站 | av不卡毛片 | av日韩在线免费观看 | 欧美日韩亚洲成人 | 久久一区国产 | 91久久久久久亚洲精品禁果 | 久久久久女人精品毛片九一 | 夜夜夜精品视频 | 黄色免费小视频网站 | 99最新网址 | 一区二区三区黄色 | 精品一区二区三区在线观看国产 | 精品一区二区三区欧美 | 成人午夜在线免费 | 国产日韩亚洲 | 国产青草视频在线观看 | 激情黄页 | 91九色精品国产 | 欧美人xx | 色综合狠狠 | 99爱视频在线观看 | 久久久久久中文字幕 | 99精品视频在线观看免费 | 国产午夜电影在线观看 | 亚洲国产超高清a毛毛片 | 免费看综艺策驰影院 | 国产自在自线午夜精品视频在 | 福利在线小视频 | 免费国产成人高清在线看软件 | 中文字幕在线观看免费 | 成人福利网 | 午夜激情视频免费 | 国产91久久精品一区二区 | 久久人人爽人人爽人人片av高请 | 欧美囗交| 久久久久女人精品毛片九一 |