Several functions for generating local files after ASP collection and warehouse receiving

Source: Internet
Author: User

ASP Website data collectionProgramProduction: several functions for generating local files from a collection database (which can be used to generate HTML static webpages)

Looking at a website system that has a collection function module, I was so worried that I would like to bring a collection module to my website. Unfortunately, I have never known how to start it, with these functions, you can also create your own collection program, and use this principle to generate HTML static Web pages.

This article describes how to implement the collection program by using the following functions:

1: savefiles (byref from, byref tofile)
Purpose: save files using streams
'Parameter: From (Remote File address), tofile (save file location)

2: isexists (byref filespec)
Purpose: Use FSO to check whether a file exists. If yes, true is returned. If no, false is returned.
'Parameter: filespes (file location)

3: isfolder (byref folder)
Purpose: Use FSO to check whether a folder exists. If yes, true is returned. If no folder exists, false is returned.
'Parameter: folder (Folder location)

4: createfolder (byref FLDR)
Purpose: Create a folder using FSO
'Parameter: FLDR (Folder location)

5: savedata (byref fromurl, byref tofiles)
Purpose: Save the file and automatically create a multi-level folder
'Parameter: fromurl (Remote File address), tofiles (storage location)

6: getdata (byref URL, byref getmode)
Role: obtain remote data
'Parameter: URL (Remote File address), getmode (Mode: 0 is binary, 1 is Chinese encoding)

7: formatimgpath (byref imgurl, byref imgfolder, byref fristname, byref noimg)
Purpose: format the remote image address as a local location.
'Parameter: imgurl (Remote Image address), imgfolder (local image directory), and fristname (prefix name)

With the above seven functions, you can create a simple website data collection program. The following describes the implementation details.Code.

'**************************** ***********************************
'function
: use stream to save files
'parameter: From (Remote File address), tofile (save file location)
'************************************ * **************************
private function savefiles (byref from, byref tofile)
dim datas
datas = getdata (from, 0)
response. write "saved successfully: " & formatnumber (LEN (datas)/1024 *) & " kb"
response. flush
If formatnumber (LEN (datas)/1024 *)> 1 then
Ados. type = 1
Ados. mode = 3
Ados. open
Ados. write datas
Ados. savetofile server. mappath (tofile), 2
Ados. close ()
else
response. write "failed to save: file size" & formatnumber (LEN (IMGs)/1024*2, 2) & "kb, less than 1 k "
response. flush
end if
end function

'*************************************** **************************
'Function (private)
'Purpose: Use FSO to check whether a file exists. If yes, true is returned. If no, false is returned.
'Parameter: filespes (file location)
'*************************************** **************************
Private function isexists (byref filespec)
If (FSO. fileexists (server. mappath (filespec) then
Isexists = true
Else
Isexists = false
End if
End Function

'*************************************** **************************
'Function (private)
'Purpose: Use FSO to check whether a folder exists. If yes, true is returned. If no folder exists, false is returned.
'Parameter: folder (Folder location)
'*************************************** **************************
Private function isfolder (byref folder)
If FSO. folderexists (server. mappath (folder) then
Isfolder = true
Else
Isfolder = false
End if
End Function

'*************************************** **************************
'Function (private)
'Purpose: Use FSO to create a folder
'Parameter: FLDR (Folder location)
'*************************************** **************************
Private function createfolder (byref FLDR)
Dim F
Set F = FSO. createfolder (server. mappath (FLDR ))
Createfolder = f. Path
Set F = nothing
End Function

'*************************************** **************************
'Function (public)
'Purpose: Save the file and automatically create a multi-level folder
'Parameter: fromurl (Remote File address), tofiles (storage location)
'*************************************** **************************
Public Function savedata (byref fromurl, byref tofiles)
Tofiles = trim (replace (tofiles ,"//","/"))
Flname = tofiles
FLDR = ""
If isexists (flname) = false then
Getnewsfold = Split (flname ,"/")
For I = 0 to ubound (getnewsfold)-1
If FLDR = "" then
FLDR = getnewsfold (I)
Else
FLDR = FLDR & "\" & getnewsfold (I)
End if
If isfolder (FLDR) = false then
Createfolder FLDR
End if
Next
Savefiles fromurl, flname
End if
End Function
'*************************************** **************************
'Function (public)
'Role: obtain remote data
'Parameter: URL (Remote File address), getmode (Mode: 0 is binary, 1 is Chinese encoding)
'*************************************** **************************
Public Function getdata (byref URL, byref getmode)
'On error resume next
Sourcecode = oxml. Open ("get", URL, false)
Oxml. Send ()
If oxml. readystate <> 4 then exit function
If getmode = 0 then
Getdata = oxml. responsebody
Else
Getdata = bytestobstr (oxml. responsebody)
End if
If err. Number <> 0 then err. Clear
End Function

'*************************************** **************************
'Function (public)
'Purpose: format the remote image address as the local location
'Parameter: imgurl (Remote Image address), imgfolder (local image directory), and fristname (prefix name)
'*************************************** **************************
Public Function formatimgpath (byref imgurl, byref imgfolder, byref fristname, byref noimg)
Strpath = ""
Imgurl = imgurl
If instr (imgurl, "nophoto") or lenb (getdata (imgurl, 0) <= 0 then
Strpath = noimg
Response. Write "<a href =" & strpath & ">" & strpath & "</a>" & vbcrlf
Else
If instr (imgurl, ". asp") then
Strpath = fristname & "_" & Mid (imgurl, faster Rev (imgurl, "=") + 1) & ". jpg"
Else
Strpath = fristname & "_" & Mid (imgurl, limit Rev (imgurl, "/") + 1)
End if
Strpath = imgfolder & "/" & strpath
Strpath = Replace (strpath ,"//","/")
If left (strpath, 1) = "/" then strpath = right (strpath, Len (strpath)-1)
Strpath = trim (strpath)
Response. Write "<a href =" & strpath & ">" & strpath & "</a>" & vbcrlf
Savedata imgurl, strpath
End if
Formatimgpath = strpath
End Function

Related Article

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.