镜头清洗液:FSO怎样得到文件的URL地址

来源:百度文库 编辑:高考问答 时间:2024/04/28 16:29:39
<%
dpath=server.mappath("\images")
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
Set MyFolder=FSO.GetFolder(dpath)
For Each document in MyFolder.Files
Response.Write("<a href='"&document&"'>"&document&"</a>"&"<br>")
Next
%>

上面的代码的得到的是文件的物理地址(C:\input\www\images\001.jpg)
而不是这个文件的url地址。我需要的是它的URL地址如(http://www.xxx.com/images/001.jpg)
请问我该怎样转换成我需要的URL格式呢

Dim sHost, sPort
sHost = Split(Request.ServerVariables("SERVER_PROTOCOL"), "/")(0) & "://" & Request.ServerVariables("HTTP_HOST")
sPort = Request.ServerVariables("SERVER_PORT")
If sPort <> "80" Then
sHost = sHost & ":" & sPort
End If
此时sHost是你的网站http地址,你在后面补齐相对目录和文件名就行