获取本地ip:远程获取内容,并将内容存在本地电脑上,包括任何文件来源: 发布时间:星期四, 2009年2月12日 浏览:331次 评论:0
<% \'------------------------------------------------------------------------ \'-------------------无垠网域:http://www.5inet.net/ --------------------- \'-------------------作者:嘻哈呵嘿 ,[email protected] ----------------- \'----------远程获取内容 ![]() ![]() \'---------------利用xmlhttp和adodb.stream,酷!绝对原创!----------------- \'On Error Resume Next \'Set the content type to the spec ![]() \'Response.ContentType = \"IMAGE/JPEG\" \'-------------------------------定义输出格式----------------------------- Path=request.query ![]() sPath = Path ![]() ![]() \'-------------如果前面没有http就是本地文件 ![]() LocalFile(path) ![]() \'--------------------否则为远程文件 ![]() RemoteFile(Path) end ![]() \'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.File ![]() \'Response.Write fileName ![]() \'--------------检查文件是否是已经访问过,如是 ![]() Response.Redirect \"/uploadfile/cache/\" & GetFileName(path) Else \'----------------否则 ![]() ![]() \'Response.Write Path t = GetBody(Path) \'-----------------用 2进制思路方法写到浏览器上-------------------------- Response.BinaryWrite t Response.Flush \'-----------------输出缓冲------------------------------------------ SaveFile t,GetFileName(path) \'------------------将文件内容缓存Cache到本地路径 ![]() End ![]() 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(l ![]() str = Replace(l ![]() 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对象 ![]() objStream.Type = adTypeBinary \'-------------以 2进制模式打开------------------------------------- objStream.Open objstream.write str \'--------------------将 ![]() \'response.Write fname objstream.SaveToFile \"c:\\inetpub\\myweb\\uploadfile\\cache\\\" & fName,adSaveCreateOverWrite \'--------------------将缓冲 ![]() \'response.BinaryWrite objstream.Read objstream.Close ![]() ![]() \'-----------------------关闭对象 ![]() \'response.Write err.Description End sub %> 0
相关文章读者评论发表评论 |