欧美成人精品手机在线观看_69视频国产_动漫精品第一页_日韩中文字幕网 - 日本欧美一区二区

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

ASP保存遠程圖片到本地,并生成縮略圖

admin
2010年7月14日 1:7 本文熱度 5597
[p]asp通過xmlhttp獲取遠程圖片流數據,并保存到本地,把第一張采集到的圖片生成縮略圖。[/p]
[p]具體代碼如下:[/p]
[p]<% [br]'================================================== [br]'函數名:checkdir2 [br]'作 用:檢查文件夾是否存在 [br]'參 數:folderpath ------文件夾地址 [br]'================================================== [br]function checkdir2(byval folderpath) [br]dim fso [br]folderpath=server.mappath(".")&"\"&folderpath [br]set fso = server.createobject("scripting.filesystemobject") [br]if fso.folderexists(folderpath) then [br]'存在 [br]checkdir2 = true [br]else [br]'不存在 [br]checkdir2 = false [br]end if [br]set fso = nothing [br]end function [br]'================================================== [br]'函數名:makenewsdir2 [br]'作 用:創建新的文件夾 [br]'參 數:foldername ------文件夾名稱 [br]'================================================== [br]function makenewsdir2(byval foldername) [br]dim fso [br]set fso = server.createobject("scripting.filesystemobject") [br]fso.createfolder(server.mappath(".") &"\" &foldername) [br]if fso.folderexists(server.mappath(".") &"\" &foldername) then [br]makenewsdir2 = true [br]else [br]makenewsdir2 = false [br]end if [br]set fso = nothing [br]end function [br]'================================================== [br]'函數名:definiteurl [br]'作 用:將相對地址轉換為絕對地址 [br]'參 數:primitiveurl ------要轉換的相對地址 [br]'參 數:consulturl ------當前網頁地址 [br]'================================================== [br]function definiteurl(byval primitiveurl,byval consulturl) [br]dim contemp,pritemp,pi,ci,priarray,conarray [br]if primitiveurl="" or consulturl="" or primitiveurl="$false$" then [br]definiteurl="$false$" [br]exit function [br]end if [br]if left(consulturl,7)<>"http://" and left(consulturl,7)<>"http://" then [br]consulturl= "http://" & consulturl [br]end if [br]consulturl=replace(consulturl,"://",":\\") [br]if right(consulturl,1)<>"/" then [br]if instr(consulturl,"/")>0 then [br]if instr(right(consulturl,len(consulturl)-instrrev(consulturl,"/")),".")>0 then [br]else [br]consulturl=consulturl & "/" [br]end if [br]else [br]consulturl=consulturl & "/" [br]end if [br]end if [br]conarray=split(consulturl,"/") [br]if left(primitiveurl,7) = "http://" then [br]definiteurl=replace(primitiveurl,"://",":\\") [br]elseif left(primitiveurl,1) = "/" then [br]definiteurl=conarray(0) & primitiveurl [br]elseif left(primitiveurl,2)="./" then [br]definiteurl=conarray(0) & right(primitiveurl,len(primitiveurl)-1) [br]elseif left(primitiveurl,3)="../" then [br]do while left(primitiveurl,3)="../" [br]primitiveurl=right(primitiveurl,len(primitiveurl)-3) [br]pi=pi+1 [br]loop [br]for ci=0 to (ubound(conarray)-1-pi) [br]if definiteurl<>"" then [br]definiteurl=definiteurl & "/" & conarray(ci) [br]else [br]definiteurl=conarray(ci) [br]end if [br]next [br]definiteurl=definiteurl & "/" & primitiveurl [br]else [br]if instr(primitiveurl,"/")>0 then [br]priarray=split(primitiveurl,"/") [br]if instr(priarray(0),".")>0 then [br]if right(primitiveurl,1)="/" then [br]definiteurl="http:\\" & primitiveurl [br]else [br]if instr(priarray(ubound(priarray)-1),".")>0 then [br]definiteurl="http:\\" & primitiveurl [br]else [br]definiteurl="http:\\" & primitiveurl & "/" [br]end if [br]end if [br]else [br]if right(consulturl,1)="/" then [br]definiteurl=consulturl & primitiveurl [br]else [br]definiteurl=left(consulturl,instrrev(consulturl,"/")) & primitiveurl [br]end if [br]end if [br]else [br]if instr(primitiveurl,".")>0 then [br]if right(consulturl,1)="/" then [br]if right(primitiveurl,3)=".cn" or right(primitiveurl,3)="com" or right(primitiveurl,3)="net" or right(primitiveurl,3)="org" then [br]definiteurl="http:\\" & primitiveurl & "/" [br]else [br]definiteurl=consulturl & primitiveurl [br]end if [br]else [br]if right(primitiveurl,3)=".cn" or right(primitiveurl,3)="com" or right(primitiveurl,3)="net" or right(primitiveurl,3)="org" then [br]definiteurl="http:\\" & primitiveurl & "/" [br]else [br]definiteurl=left(consulturl,instrrev(consulturl,"/")) & "/" & primitiveurl [br]end if [br]end if [br]else [br]if right(consulturl,1)="/" then [br]definiteurl=consulturl & primitiveurl & "/" [br]else [br]definiteurl=left(consulturl,instrrev(consulturl,"/")) & "/" & primitiveurl & "/" [br]end if [br]end if [br]end if [br]end if [br]if left(definiteurl,1)="/" then [br]definiteurl=right(definiteurl,len(definiteurl)-1) [br]end if [br]if definiteurl<>"" then [br]definiteurl=replace(definiteurl,"http://","/") [br]definiteurl=replace(definiteurl,":\\","://") [br]else [br]definiteurl="$false$" [br]end if [br]end function [br]'================================================== [br]'函數名:replacesaveremotefile [br]'作 用:替換、保存遠程文件 [br]'參 數:constr ------ 要替換的字符串 [br]'參 數:starstr ----- 前導 [br]'參 數:overstr ----- [br]'參 數:inclul ------ [br]'參 數:inclur ------ [br]'參 數:savetf ------ 是否保存文件,false不保存,true保存 [br]'參 數:savefilepath- 保存文件夾 [br]'參 數: tisturl------ 當前網頁地址 [br]'================================================== [br]function replacesaveremotefile(constr,startstr,overstr,inclul,inclur,savetf,savefilepath,tisturl) [br]if constr="$false$" or constr="" then [br]replacesaveremotefile="$false$" [br]exit function [br]end if [br]dim tempstr,tempstr2,ref,matches,match,tempi,temparray,temparray2,overtypearray [br][br]set ref = new regexp [br]ref.ignorecase = true [br]ref.global = true [br]ref.pattern = "("&startstr&").+?("&overstr&")" [br]set matches =ref.execute(constr) [br]for each match in matches [br]if instr(tempstr,match.value)=0 then [br]if tempstr<>"" then [br]tempstr=tempstr & "$array$" & match.value [br]else [br]tempstr=match.value [br]end if [br]end if [br]next [br]set matches=nothing [br]set ref=nothing [br]if tempstr="" or isnull(tempstr)=true then [br]replacesaveremotefile=constr [br]exit function [br]end if [br]if inclul=false then [br]tempstr=replace(tempstr,startstr,"") [br]end if [br]if inclur=false then [br]if instr(overstr,"|")>0 then [br]overtypearray=split(overstr,"|") [br]for tempi=0 to ubound(overtypearray) [br]tempstr=replace(tempstr,overtypearray(tempi),"") [br]next [br]else [br]tempstr=replace(tempstr,overstr,"") [br]end if [br]end if [br]tempstr=replace(tempstr,"""","") [br]tempstr=replace(tempstr,"'","") [br][br]dim remotefile,remotefileurl,savefilename,savefiletype,arrsavefilename,rannum [br]if right(savefilepath,1)="/" then [br]savefilepath=left(savefilepath,len(savefilepath)-1) [br]end if [br]if savetf=true then [br]if checkdir2(savefilepath)=false then [br]if makenewsdir2(savefilepath)=false then [br]savetf=false [br]end if [br]end if [br]end if [br]savefilepath=savefilepath & "/" [br][br]'圖片轉換/保存 [br]temparray=split(tempstr,"$array$") [br]for tempi=0 to ubound(temparray) [br]remotefileurl=definiteurl(temparray(tempi),tisturl) [br]if remotefileurl<>"$false$" and savetf=true then'保存圖片 [br]arrsavefilename = split(remotefileurl,".") [br]savefiletype=arrsavefilename(ubound(arrsavefilename))'文件類型 [br]rannum=int(900*rnd)+100 [br]savefilename = savefilepath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum&"."&savefiletype [br]call saveremotefile(savefilename,remotefileurl) [br]constr=replace(constr,temparray(tempi),savefilename) [br]elseif remotefileurl<>"$false$" and savetf=false then'不保存圖片 [br]savefilename=remotefileurl [br]constr=replace(constr,temparray(tempi),savefilename) [br]end if [br]if remotefileurl<>"$false$" then [br]if uploadfiles="" then [br]uploadfiles=savefilename [br]else [br]uploadfiles=uploadfiles & "|" & savefilename [br]end if [br]end if [br]next [br]replacesaveremotefile=constr [br]end function [br]'================================================== [br]'過程名:saveremotefile [br]'作 用:保存遠程的文件到本地 [br]'參 數:localfilename ------ 本地文件名 [br]'參 數:remotefileurl ------ 遠程文件url [br]'================================================== [br]sub saveremotefile(localfilename,remotefileurl) [br]dim ads,retrieval,getremotedata [br]set retrieval = server.createobject("microsoft.xmlhttp") [br]with retrieval [br].open "get", remotefileurl, false, "", "" [br].send [br]getremotedata = .responsebody [br]end with [br]set retrieval = nothing [br]set ads = server.createobject("adodb.stream") [br]with ads [br].type = 1 [br].open [br].write getremotedata [br].savetofile server.mappath(localfilename),2 [br].cancel() [br].close() [br]end with [br]set ads=nothing [br]end sub [br][br]'================================================== [br]'過程名:getimg [br]'作 用:取得文章中第一張圖片 [br]'參 數:str ------ 文章內容 [br]'參 數:strpath ------ 保存圖片的路徑 [br]'================================================== [br]function getimg(str,strpath) [br]set objregex = new regexp [br]objregex.ignorecase = true [br]objregex.global = true [br]zzstr=""&strpath&"(.+?)\.(jpg|gif|png|bmp)" [br]objregex.pattern = zzstr [br]set matches = objregex.execute(str) [br]for each match in matches [br]retstr = retstr &"|"& match.value [br]next [br]if retstr<>"" then [br]imglist=split(retstr,"|") [br]imgone=replace(imglist(1),strpath,"") [br]getimg=imgone [br]else [br]getimg="" [br]end if [br]end function [br]%> [br][br]例: [br][br]程序代碼 [br]
[br] [br] [br]
[br]<% [br]if request.querystring("action")="test" then [br]'圖片開始的字符串 [br]filesstartstr="src=" [br]'圖片結束的字符串 [br]filesoverstr="gif|jpg|bmp" [br]'保存圖片的文件夾 [br]filespath="qq" [br]'取得保存圖片的網站url 自動判斷是絕對 還是相對路徑 [br]newsurl="http://news.163.com" [br]'取得文章內容 [br]content =request.form("body") [br]'開始保存圖片 [br]content=replacesaveremotefile(content,filesstartstr,filesoverstr,false,true,true,filespath,newsurl) [br]'對新聞中的第一張圖片創建縮略圖 [br]if getimg(content,filespath)<>"" then [br]imgsrc=getimg(content,filespath) [br]imgsrc=replace(imgsrc,filespath,"") [br]set jpeg = server.createobject("persits.jpeg") [br]path = server.mappath(""&filespath&"") & "\"&imgsrc&"" [br]jpeg.open path [br]'如果圖片寬小于等于120 高小于等于90 則不創建縮略圖 [br]if jpeg.originalwidth<=120 and jpeg.height<=90 then [br]jpeg.width = jpeg.originalwidth [br]jpeg.height = jpeg.originalheight [br]smallimg=filespath&""&getimg(content,filespath) [br]else [br]'圖片寬度高度/2 [br]jpeg.width = jpeg.originalwidth / 2 [br]jpeg.height = jpeg.originalheight / 2 [br]jpeg.save server.mappath(""&filespath&"") & "\small_"&imgsrc&"" [br]smallimg=""&filespath&"/small_"&imgsrc&"" [br]end if [br]end if [br]'顯示結果 [br]response.write("新聞中的第一張圖片是:") [br]response.write("") [br]response.write("
新聞中的第一張圖片的縮略圖是:") [br]response.write("") [br]response.write("
新的新聞內容(圖片為本地):
") [br]response.write(content) [br]response.end() [br]end if [br]%>[/p]

該文章在 2010/7/14 1:07:47 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved