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 %> |