如何获得一个文件的完整URL地址?

agame 2003-05-05 03:59:10
假设网站URL是http://www.myname.com/
我在网站根目录下放了一个文件test.txt

我现在要是一个ASP页面上用什么方法能得到test.txt的完整URL地址“http://www.myname.com/test.txt”?

这个问题感觉好象挺简单的,我就是想不起来怎么搞了。
...全文
430 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
heezi 2003-05-05
  • 打赏
  • 举报
回复
我不知道你是不是在根目录下了,我说了咯,要取得文件夹路径再跟贴嘛!
hohoho
agame 2003-05-05
  • 打赏
  • 举报
回复
自己解决了。

思路:先得到test.asp的完整URL路径,然后split到一个数组中,redim数组大小(减去1),然后join数组,得到路径后拼接文件名称。

如果是直接在根目录下就没什么意义了,太简单了。如果是test.asp在根目录下,test.txt在file目录下就有点玩头了。
agame 2003-05-05
  • 打赏
  • 举报
回复
TO:heezi(何之)

呵呵,以上所有程序我都能看懂,不过确实是不正确的。

你写的Url="http://"&request.servervariable("server_name")最后得到的结果是

http://www.myname.com

如此而已。我想你没有仔细看明白我的问题。
agame 2003-05-05
  • 打赏
  • 举报
回复
你改错了,象你这样改的话最后出来的是:

http://www.myname.com/test.asp?/test.txt

看明白了吗?

如果真是要该这个函数的话只要加个功能把test.asp去掉,替换成test.txt就行了。
heezi 2003-05-05
  • 打赏
  • 举报
回复
<%
dim Url
Url="http://"&request.servervariable("server_name")
'这个是取得主机地址
'如果你还要取得文件夹地址的话那再跟贴了
%>

上面的那位老兄可能写的太复杂了一点你看不懂是吧他大的语句是绝对有效滴!
fason 2003-05-05
  • 打赏
  • 举报
回复
你把函数改改就行了
<%
Function GetUrl(txt)
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp+"/"+txt
End Function
Response.write GetUrl("test.txt")
%>
agame 2003-05-05
  • 打赏
  • 举报
回复
顶啊,以上啊信回复的都不是正解,正确回答者送150分!
fason 2003-05-05
  • 打赏
  • 举报
回复
哦,好象错了
<%=server.mappath("test.txt")%>
fason 2003-05-05
  • 打赏
  • 举报
回复
得到当前页面的地址
<%
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function
Response.write GetUrl()
%>
agame 2003-05-05
  • 打赏
  • 举报
回复
沉的太快了,哪为可以帮我分析一下?谢谢了!
agame 2003-05-05
  • 打赏
  • 举报
回复
注:ASP页面和test.txt在同一目录下。

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧