- 热门文章:
- · ASP漏洞及安全建议
- · 闰年的判别
- · 计算文件下载时间
- · ASP的函数详解
- · 一个取图片尺寸的类,支持jpg,gif,png
- · JS错误代码解释大全
- · 窗口最大化的严格定义
- · 一個簡單的驗証碼
- · 17种正则表达式
- · 一个非常简洁的验证码程序
- · 今天做了一个ASP计数器,放出源码吧,挺简单的!
- · 个性化的表单验证效果
上一篇:ASP提速技巧五则 >>
利用ASP远程获取内容
‘’----------远程获取内容,并将内容存在本地电脑上,包括任何文件!----------
‘’---------------利用xmlhttp和adodb.stream,酷!绝对原创!-----------------
‘’On Error Resume Next
‘’Set the content type to the specific type that you are sending.
‘’Response.ContentType = "IMAGE/JPEG"
‘’-------------------------------定义输出格式-----------------------------
Path=request.querystring("p")
sPath = Path
if left(lcase(path),7) <> "http://" then
‘’-------------如果前面没有http就是本地文件,交给LocalFile处理------------
LocalFile(path)
else
‘’--------------------否则为远程文件,交给RemoteFile处理------------------
RemoteFile(Path)
end if
‘’Response.Write err.Description
sub LocalFile(Path)
‘’-------------------如果为本地文件则简单的跳转到该页面-------------------
Response.Redirect Path
End Sub
Sub RemoteFile(sPath)
‘’-------------------------处理远程文件函数------------------------------
FileName = GetFileName(sPath)
‘’-------------GetFileName为把地址转换为合格的文件名过程-------------
FileName = Server.MapPath("/UploadFile/Cache/" & FileName)
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
‘’Response.Write fileName
if objFso.FileExists(FileName) Then
‘’--------------检查文件是否是已经访问过,如是,则简单跳转------------
Response.Redirect "/uploadfile/cache/" & GetFileName(path)
Else
‘’----------------否则的话就先用GetBody函数读取----------------------
‘’Response.Write Path
t = GetBody(Path)
‘’-----------------用二进制方法写到浏览器上--------------------------
Response.BinaryWrite t
Response.Flush
‘’-----------------输出缓冲------------------------------------------
SaveFile t,GetFileName(path)
‘’------------------将文件内容缓存到本地路径,以待下次访问-----------
End if
Set objFso = Nothing
End Sub
Function GetBody(url)
‘’-----------------------本函数为远程获取内容的函数---------------------
‘’on error resume next
‘’Response.Write url
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
‘’----------------------建立XMLHTTP对象-----------------------------
With Retrieval
.Open "Get", url, False, "", ""
‘’------------------用Get,异步的方法发送-----------------------
.Send
‘’GetBody = .ResponseText
GetBody = .ResponseBody
‘’------------------函数返回获取的内容--------------------------
End With
Set Retrieval = Nothing
‘’response.Write err.Description
End Function
Function GetFileName(str)
‘’-------------------------本函数为合格化的文件名函数-------------------
str = Replace(lcase(str),"http://","")
str = Replace(lcase(str),"//","/")
str = Replace(str,"/","")
str = replace(str,vbcrlf,"")
GetFileName = str
End Function
sub SaveFile(str,fName)
‘’-------------------------本函数为将流内容存盘的函数-------------------
‘’on error resume next
Set objStream = Server.CreateObject("ADODB.Stream")
‘’--------------建立ADODB.Stream对象,必须要ADO 2.5以上版本---------
objStream.Type = adTypeBinary
‘’-------------以二进制模式打开-------------------------------------
objStream.Open
objstream.write str
‘’--------------------将字符串内容写入缓冲--------------------------
‘’response.Write fname
objstream.SaveToFile "c:\inetpub\myweb\uploadfile\cache\" & fName,adSaveCreateOverWrite
‘’--------------------将缓冲的内容写入文件--------------------------
‘’response.BinaryWrite objstream.Read
objstream.Close()
set objstream = nothing
‘’-----------------------关闭对象,释放资源-------------------------
‘’response.Write err.Description
End sub
%>
下一篇:ASP漏洞及安全建议 >>
相关文章:
- · 利用ASP得到图片尺寸大小
- · 如何处理ASP中的图象
- · 精华asp代码
- · ASP中的函数说明
- · FileCopy
- · 事务处理
- · ASP中得到用户的真实IP地址
- · ASP编程中15个非常有用的例子
- · InStrRev 函数
- · 新写的一个定时新闻小偷
- · 一段自动补位的函数(ASP)
- · VBS 中 Space 函数的应用
- · 游走于ASP与ASP.NET的郁闷
- · 用ASP的安全验证来对windows 2000的管理者密码进行在线修改
- · ADSI,使用ASP来完成NT管理
- · 被ASP的小问题难倒!
- · 域名查询系统--适合新手
- · asp模块化分页
- · ASP分页显示详论
- · Iframe高度自适应
- · 正则表达式大全
- · WMI学习
- · Session 详解
- · 关于交叉报表的动态实现
- · 页面执行需要长时间时向用户的提示信息
- · 使用Repeater模板 二
- · Sucess On a Horse
- · 校友通讯资料管理系统(1)
- · ASP实现图片上存
- · 提高网站在搜索引擎中的排名
- · 关于无组上传的老话题
- · 如何实现图片的随机生成与显示
- · 怎么把webapplication打包成安装文件
- · 为treeview添加客户端事件
- · 如何让不同的语言版本显示正确的中文?
- · 线程的处理(2)
- · 线程的处理(1)
- · 再谈ASP防止SQL Injection漏洞的问题
