I recently made a music station, music file... It is generally collected from the Internet .. So .. Write a collection Section Program .
CopyCode The Code is as follows: <%
On Error resume next
Const uploadpath = "/uploads/" 'file storage path
Const allowfileext = "JPG, WMA, SwF, GIF" 'file type that can be collected
& Apos; const allowfilesize = "200"
Function GetFile (URL)
If url = "" then
Exit Function
Else
Url = trim (URL)
End if
'Get the file
Fileext = lcase (mid (URL, limit Rev (URL, ".") + 1) 'file type
Filename = lcase (mid (URL, limit Rev (URL, "/") + 1, limit Rev (URL ,". ")-faster Rev (URL,"/")-1) 'No file type file name
Newfilepath = getnow ("date") & "_" & replace (formatdatetime (now (), 3), ":", "") & "_" & cleanfilename (filename) &". "& fileext
If instr ("," & lcase (allowfileext) & "," & fileext & ",") = 0 then
GetFile = "the file type is not allowed"
Exit Function
End if
Set XMLHTTP = server. Createobject ("Microsoft. XMLHTTP ")
XMLHTTP. Open "get", URL, false
XMLHTTP. Send
'While XMLHTTP. readystate <> 4
'Xmlhttp. waitforresponse 1000
'Wend
If XMLHTTP. Status <> 200 then
GetFile = "An error occurred while obtaining the file"
Exit Function
Else
Set folder = server. Createobject ("scripting. FileSystemObject ")
Dim Foldername
Foldername = getnow ("year") & getnow ("month") 'folder
If folder. folderexists (server. mappath (uploadpath) = false then
Folder. createfolder server. mappath (uploadpath)
End if
If folder. folderexists (server. mappath (uploadpath & Foldername) = false then
Folder. createfolder server. mappath (uploadpath & Foldername)
End if
Set folder = nothing
File = XMLHTTP. responsebody
If lenb (File)> allowfilesize then
GetFile = "the file is too large to be saved! "
Exit Function
Else
Set objadostream = server. Createobject ("ADODB. Str" & "EAM ")
Objadostream. open ()
Objadostream. type = 1
Objadostream. Write (file)
Objadostream. savetofile (server. mappath (uploadpath & Foldername & "/" & newfilepath ))
Objadostream. seteos
Set objadostream = nothing
GetFile = "<a href =" "& uploadpath & Foldername &"/"& newfilepath &" target = "" _ balnk ""> collection successful </a>"
End if
End if
Set XMLHTTP = nothing
End Function
%>
<SCRIPT runat = "server" Language = "jscript">
Function cleanfilename (STR ){
STR = Str. Replace (/[^ _ \. A-Za-Z \ D]/ig ,"");
STR = Str. Replace (/^ [\/\.] + /,"");
Return STR;
}
Function getnow (N)
{
D = new date ();
Switch (N)
{
Case "year ":
Return D. getyear ();
Case "month ":
Return (D. getmonth () + 1 );
Case "date ":
Return D. getdate ();
}
}< br>
<% if request ("do") = "GetFile" and request ("file ") <> "" Then
response. write (GetFile (Request ("file")
else %>
<% end if %>