Save remote picture function Modify Genuine

Source: Internet
Author: User
Tags insert modify
function to take advantage of today's free, fixed a bit of this function, tested, in the local server through, the space quotient server can also be used normally, no errors found. My Kaspersky doesn't report poison. ^_^





as long as the change, this function is placed on which site is applicable. Here just to add a picture to illustrate the call method, other location methods similar.





in my native test success, because now not even on the space of the FTP, so no office in the space test, find problems, please come to the group.





One, put the following function into the ft_admin_conn.asp of the last





'==================================


' = function name: Saveimgfile


' = function: Save remote picture


' = parameter description: imgfileurl--remote picture Address


' = Modified Date: 2006-4-19 13:20


' = Program Author: Cold Wind


' = website: http://www.4fnet.com.cn


'==================================


function Saveimgfile (imgfileurl)


Dim Img_type,savepath,imgfiletype,flag,imgbody


savepath= ". /fuploadfile/"&year" (Now ()) & "-" &month (Now ())


Flag=false


imgfiletype=right (imgfileurl,4) ' Get the format of a remote picture


img_type= ". Gif|. bmp|. Jpg|. PNG "' setting allows you to save the picture format locally


Typearr=split (img_type, "|")


For i=0 to UBound (Typearr)-1


if Imgfiletype=typearr (i) then


flag=true


Exit For


End If


Next


if Flag=false then ' if you are not allowed to save to a local picture format, only remote pictures are connected


Saveimgfile=imgfileurl


Else


set Xml_http=server.createobject ("Microsoft.XMLHTTP")


Xml_http.open "Get", Imgfileurl,false


Xml_http.send


Imgbody=xml_http.responsebody


Set xml_http=nothing


Serverpath=server.mappath (Savepath)


set Filefolder=server.createobject ("Scripting.FileSystemObject")


if Filefolder.folderexists (serverpath) =false then


Filefolder.createfolder (Serverpath)


End If


Randomize


savepath=savepath& "/" &year (Now ()) &month (today ()) &day (now ()) &hour &minute ) &int (10*rnd) &imgfiletype


Set Adodbs=server.createobject ("ADODB.stream")


Adodbs.open


adodbs.type=1


Adodbs.write imgbody


Adodbs.savetofile (Server.MapPath (Savepath)) ' Save to local


Adodbs.seteos


Set adodbs=nothing


if Filefolder.fileexists (Server.MapPath (savepath)) =false Then ' If the save succeeds, return the remote address, only makes the remote connection, avoids some anti-theft even the website cannot save


Saveimgfile=imgfileurl


Else


Savepath=replace (Savepath, ". /","")


Saveimgfile=savepath


End If


Set filefolder=nothing


End If


End Function





Two, open admin/admin_pic.asp file


1, find: Add picture process pic_pic=checksql ("Thumbnail image address", Request.Form ("pic"), 1,100) (presumably in line No. 368) Insert code below:





if left (pic_url,7) = "http://" and Request.Form ("save") = "true" then


pic_url=saveimgfile (Pic_url)


Pic_pic=pic_url


End If


Find again: <input type= "Submit" name= "Submit" value= "OK Add" > (presumably on line No. 481) Insert the following code:





<input type= "checkbox" Name= "Save" value= "true" > Save remote Picture at the same time





2, add the corresponding code in the same place in the edit picture process (Editpic).





OK, finished





hope you can give a return, other use of the picture is the same place to invoke the method.





Welcome to our website: http://www.4fnet.com.cn





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.