這是一段用ASP程序獲取遠程文件大小的函數,看起來很簡單,icech推薦給大家學習一下:
<%
'-----------------------------------------------------------
'功能:獲取遠程文件大小
'參數:url 遠程文件地址
'返回:遠程文件大小(單位:字節)
'-----------------------------------------------------------
Function getRemoteFileSize(url)
Dim xmlHTTP
Set xmlHTTP = Server.CreateObject("MSXML2.XMLHTTP")
xmlHTTP.open "get", url, false
'下一句非常關鍵,否則要預加載全部的文件信息后才返回header頭信息
xmlHTTP.setRequestHeader "range", "bytes=-1"
xmlHTTP.send()
getRemoteFileSize = Split(xmlHTTP.GetResponseHeader("Content-Range"),"/")(1)
Set xmlHTTP = Nothing
End Function
Response.Write(getRemoteFileSize("http://js.tongji.cn.yahoo.com/i.gif"))
%>