A simple self-creating file upload

Source: Internet
Author: User
Tags end file upload
Upload

A simple ASP file upload source code example, streamlined and practical.

Here's the upload.asp code:
<form name= "form" action= "upload.asp" method= "POST" >
<input type= "Submit" name= "Submit" value= "OK" >
<input type= "File" Name= "File1" style= "width:400" "value=" ">
<input type=text name=myface size=20 maxlength=100>
</form>
<%
If Request.Form ("File1") <> "" Then
Dim allowext_ ' Allow upload type (whitelist)
Dim Noallowext_ ' does not allow upload type (blacklist)
Noallowext= "Exe;gif" blacklist, you can preset the file type cannot be uploaded here, to the file suffix name to judge, not case, each prefix with the name of a separate, if the blacklist is empty, then judge the white list
Noallowext=lcase (Noallowext)
allowext= "" ' Whitelist, where you can preset the file type to upload, to the file suffix name to judge, no case, each suffix name with;
Allowext=lcase (Allowext)

Function GetFileName (ByVal strfile)
If strfile <> "" Then
GetFileName = Mid (Strfile,instrrev (strfile, "\") +1)
Else
GetFileName = ""
End If
End Function
Function Isallowext (EXT)
If noallowext= "" Then
Isallowext=cbool (INSTR (1, ";") &AllowExt& ";", LCase (";") &Ext& "))
Else
Isallowext=not CBool (INSTR (1, ";") &NoAllowExt& ";", LCase (";") &Ext& "))
End If
End Function
Public Function Getfileext (FullPath)
If fullpath <> "" Then
Getfileext = LCase (Mid (Fullpath,instrrev (FullPath, ".") +1))
Else
Getfileext = ""
End If
End Function

Uppath= "Uploadfile\"
strFileName = Request.Form ("File1")
Strnum=trim (Len (strFileName))
Filetype= Mid (strfilename,strnum-2,3)
If Isallowext (filetype) Then
Set objstream = Server.CreateObject ("ADODB. Stream ")
objStream.Type = 1 ' adtypebinary
objStream.Open
objStream.LoadFromFile strFileName
Objstream.savetofile Server.MapPath (Uppath&getfilename (strFileName)), 2
objStream.Close
Response.Write "<script>parent.document.forms[0].myface.value= '" &uppath& "/" &getfilename ( strFileName) & "' </script>"
Response.Write "<a href= '" &uppath&getfilename (strFileName) & "' > View Avatar </a>"
Response.Write "File type:" &filetype& ""
Else
Response.Write "<script language=javascript>alert (' avatar file only allowed in GIF file format! ');"
Response.Write "This.location.href= ' Javascript:history.back (); ' </SCRIPT> "
Response.End
End If
End If
%>



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.