複製代碼 代碼如下:<%
'建立檔案夾函數
Function CreateFolder(strFolder)'參數為相對路徑
'首選判斷要建立的檔案夾是否已經存在
Dim strTestFolder,objFSO
strTestFolder = Server.Mappath(strFolder)
Set objFSO = CreateObject("Scripting.FileSystemObject")
'檢查檔案夾是否存在
If not objFSO.FolderExists(strTestFolder) Then
'如果不存在則建立檔案夾
objFSO.CreateFolder(strTestFolder)
End If
Set objFSO = Nothing
End function
'刪除檔案夾
Function DelFolder(strFolder)'參數為相對路徑
strTestFolder = Server.Mappath(strFolder)
Set objFSO = CreateObject("Scripting.FileSystemObject")
'檢查檔案夾是否存在
If objFSO.FolderExists(strTestFolder) Then
objFSO.DeleteFolder(strTestFolder)
end if
Set objFSO = Nothing
End function
'建立文字檔
Function Createtextfile(fileurl,filecontent)'參數為相對路徑和要寫入檔案的內容
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set fout = objFSO.CreateTextFile(Server.MapPath(fileurl))
fout.WriteLine filecontent
fout.close
Set objFSO = Nothing
End Function
'刪除檔案(適合所有檔案)
Function Deltextfile(fileurl)'參數為相對路徑
Set objFSO = CreateObject("Scripting.FileSystemObject")
fileurl = Server.MapPath(fileurl)
if objFSO.FileExists(fileurl) then '檢查檔案是否存在
objFSO.DeleteFile(Server.mappath(fileurl))
end if
Set objFSO = nothing
End Function
'建立圖片檔案並儲存圖片資料流
Function Createimage(fileurl,imagecontent)'參數為相對路徑和檔案內容
Set objStream = Server.CreateObject("ADODB.Stream") '建立ADODB.Stream對象,必須要ADO 2.5以上版本
objStream.Type =1 '以二進位模式開啟
objStream.Open
objstream.write imagecontent '將字串內容寫入緩衝
objstream.SaveToFile server.mappath(fileurl),2 '-將緩衝的內容寫入檔案
objstream.Close()'關閉對象
set objstream=nothing
End Function
'遠程擷取檔案資料
Function getHTTPPage(url)
'On Error Resume Next
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
If Err.number<>0 then
getHTTPPage = "伺服器擷取檔案內容出錯"
Err.Clear
End If
End function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'擷取圖片資料流
Function getpic(url)
on error resume next
dim http
set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法來獲得圖片的內容
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getpic=Http.responseBody
set http=nothing
if err.number<>0 then
getpic = "伺服器擷取檔案內容出錯"
err.Clear
End if
End Function
'開啟檔案(文本形式)
Function OpenFile(fileurl)'檔案相對路徑
Dim Filename,fso,hndFile
Filename = fileurl
Filename = Server.MapPath(Filename)
Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.FileExists(Filename) Then
set hndFile = objfso.OpenTextFile(Filename)
OpenFile = hndFile.ReadAll
Else
OpenFile = "檔案讀取錯誤"
End If
Set hndFile = Nothing
Set objfso = Nothing
End Function
'獲得檔案的尾碼名
function getFileExtName(fileName)
dim pos
pos=instrrev(filename,".")
if pos>0 then
getFileExtName=mid(fileName,pos+1)
else
getFileExtName=""
end if
end function
%>