function | upload | No component This function is to upload files with "Transformation ASP no component Upload Program 2.0".
Core functions:
<%
'''''==============================
' Function name: upfile
' Function: Use ' transformation upload component ' to upload files to server
' Parameter: File1 file object
' Savepath file to save relative path, such as '. /"record at the top level," "the same directory
' MaxSize allows the maximum file size to be uploaded, in kilobytes KB. is 0 Unlimited.
' Savetype allows the type of file to be uploaded, 0 unrestricted, restricted format. such as. Jpg|. bmp|. Zip
' Return value: Returns the upload information, but also can set the return value according to the need
' Premise: Set upload=new upload_5xsoft ' Build upload Object
' Set File1=upload.file (' file1 ') ' generates a File object
' Designer:suercool
function Upfile (file1,savepath,maxsize,savetype)
If File1.filename= "" and file1.filesize<=0 Then
upfile= "<script language= ' JavaScript ' >alert (' file does not exist! ') </script> "
Exit function
End If
If maxsize<> "0" and FILE1.FILESIZE>CLNG (maxsize) *1024 Then
upfile= "<script language= ' JavaScript ' >alert (' file size exceeds the limit, maximum upload only" & CStr (maxsize) & "KB files! ') </script> "
Exit function
End If
Dim Filename,filetype
Filename=file1.filename
Filetype=getfiletype (filename)
If savetype<> "0" Then
Dim Arrtype,i,foundtype
Arrtype=split (Savetype, "|")
Foundtype=false
For i = 0 To UBound (arrtype)
If LCase (Arrtype (i)) =filetype then
Foundtype=true
Exit For
End If
Next
If not Foundtype then
upfile= "<script language= ' JavaScript ' >alert (' file format is not accurate, only allowed to upload ' & savetype & ' Format Files! ') </script> "
Exit function
End If
End If
Randomize ()
Filepath=savepath&year (now) &month-&day (now) &hour (now) &minute (now) &second (now) & Int (rnd*9999) &filetype
File1.saveas Server.MapPath (filepath)
If err.description<> "" Then
upfile= "<script language= ' JavaScript ' >alert (' unknown error, upload failed, please try again! ') </script> "
Err.Clear
Else
upfile= "<script language= ' JavaScript ' >alert (' upload success! ') +filepath+ "');</script>"
End If
Set file1=nothing
End Function
''''''''===========
' Function name: Getfiletype
' Function: Get the type of file
' parameter: filename filename
' Return value: File type, no type return '
' Designer:suercool
function Getfiletype (filename)
Dim i
For i= (len (filename)-1) to 1 step-1
If mid (filename,i,1) = "." Then
Getfiletype=lcase (Mid (Filename,i))
Exit function
End If
Next
Getfile= ""
End Function
%>
Instance (upfile3.asp):
<!--#include file= "Upload_5xsoft.inc"-->
<title>Upfile</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<form action= "upfile3.asp" name= "Frmupfile" id= "Frmupfle" enctype= "Multipart/form-data" method=post>
<input type=file name= "File1" >
<input type=submit value= "Upload" name=subupfile>
<input type=hidden name= "upfilename" value= "" >
<% set Upload=new upload_5xsoft ' Set up an uploaded object
If Upload.form ("subupfile") = "Upload" Then
Set File1=upload.file ("File1")
Dim re
Savetype= ". Jpg|. Htm|. Bmp| "
Re=upfile (File1, "", "0", Savetype)
Response.Write RE
End If
%>
</form>
</body>