Custom functions commonly used to process file uploads and deletions in asp:
<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' All custom VBS functions
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function DeleteFile (Filename) ' Delete file
If filename<> "" Then
Set FSO = server. CreateObject ("Scripting.FileSystemObject")
If FSO. FileExists (Filename) Then
Fso. DeleteFile Filename
End If
Set fso = Nothing
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Createdir (ByVal localpath) ' Directory-building program, if there is a multilevel directory, then one-level creation
On Error Resume Next
LocalPath = replace (LocalPath, "\", "/")
Set fileobject = Server.CreateObject ("Scripting.FileSystemObject")
Patharr = Split (LocalPath, "/")
Path_level = UBound (Patharr)
For i = 0 to Path_level
If I=0 then Pathtmp=patharr (0) & "/" Else Pathtmp = pathtmp & Patharr (i) & "/"
CPath = Left (Pathtmp,len (pathtmp)-1)
If not fileobject.folderexists (CPath) then Fileobject.createfolder CPath
Next
Set FileObject = Nothing
If Err.number<>0 Then
Createdir = False
Err. Clear
Else
Createdir = True
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Saverandfilename (ByVal szfilename) ' generates a new random filename based on the original file name
Randomize
' Rannum=int (90000*rnd) +10000
' If month (now) <10 then c_month= ' 0 ' & month [now] else C_month=month (now)
' If day ' <10 then c_day= ' 0 ' & ' Today ' else C_day=day (now)
' If hour (now) <10 then c_hour= ' 0 ' & hour [now] else C_hour=hour (now)
' If Minute (now) <10 then c_minute= ' 0 ' & minute [now] else C_minute=minute (now)
' If second (now) <10 then c_second= ' 0 ' & second [now] else C_second=minute (now)
Fileext_a=split (szFileName, ".")
Fileext=lcase (Fileext_a (UBound (fileext_a))
Saverandfilename=replace (replace (now, ":", ""), "-", ""), "", "") &int (10*RND) & "." &fileext
' Generaterandomfilename = year (now) &c_month&c_day&c_hour&c_minute&c_second& "_" & rannum& "." &fileext
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function Jaron_replacer (strcontent,start_string,end_string,replace_string)
' CMS replacement function: Source string, front section, back section, replaced by character
' Returns the replaced string
Jaron_replacer = replace (Strcontent,mid (Strcontent,instr (strcontent,start_string), InStr (strcontent,end_string) + Len (end_string)-1), replace_string)
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function Replaceplus (strcontent,start_string,end_string,replace_string)
' Document, will all begin and end with all the characters removed
On Error Resume Next
Markcounts = UBound (Split (strcontent,start_string))
prestring = strcontent
For I=0 to Markcounts
Startmark=instr (1,prestring,start_string,1)
If Startmark=0 then exit for
Compmark=instr (1,prestring,end_string,1) + len (end_string)
Verstring=mid (Prestring,startmark,compmark-startmark)
prestring = replace (prestring,verstring,replace_string)
Next
Replaceplus = prestring
If Err.number<>0 then err. Clear
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%>