ASP File Upload - Limit File Types?

Discussion in 'ASP General' started by lazyadmin, Jan 7, 2005.

  1. lazyadmin

    lazyadmin Guest

    I would like to use this code on my website to allow simple file uploads
    from clients. I would like to restrict the file types they can upload.
    Can this be done? Any help appreciated.

    Rod
    http://www.thelazyadmin.com

    ASP Code upload_file.asp

    <% @Language=VBScript %>
    <HTML>
    <HEAD>
    <TITLE>FileUp Upload Simple Sample</TITLE>
    </HEAD>
    <BODY>
    <%
    Dim oFileUp
    '--- Instantiate the FileUp object
    Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
    '--- Set the Path property to the location you wish to temporarily
    cache the incoming file before saving
    oFileUp.Path = Server.MapPath("uploads\data")
    '--- Check if a file was selected (myFile is coming from the html
    code)
    '--- If so, continue processing
    If Not oFileUp.Form("myFile").IsEmpty Then
    '--- Save the file
    oFileUp.Form("myFile").Save
    '--- The file is saved, display a confirmation message
    Response.Write ("<B>File saved successfully on the server
    as:</B><BR>")
    '--- The ServerName() property is the full path of the file where it
    was saved on the server
    Response.Write(oFileUp.Form("myFile").ServerName)
    Else
    Response.Write("Error: There was no file submitted for upload.")
    End If
    '--- Destroy objects
    Set oFileUp = Nothing
    %>


    Webpage Code Upload_File_Form.html

    </BODY>
    </HTML>
    Sample Upload Form (upload_file_form.html)
    <HTML>
    <HEAD>
    <TITLE>FileUp Simple Upload Sample</TITLE>
    </HEAD>
    <BODY>
    <H3 ALIGN=center>&nbsp;</H3>
    <H3 ALIGN=center>Asp FileUp Upload Sample</H3>
    <p ALIGN=center>&nbsp;</p>
    <FORM ACTION="fileUp.asp" ENCTYPE="MULTIPART/FORM-DATA"
    METHOD="POST">
    <TABLE WIDTH="100%">
    <TR>
    <TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>
    <!--
    Note: Notice this form element is of TYPE="FILE"
    -->
    <TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile" size="20"><BR>
    Please click Browse to select a file.</TD>
    </TR>
    <TR>
    <TD ALIGN="RIGHT">&nbsp;</TD>
    <TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>
    lazyadmin, Jan 7, 2005
    #1
    1. Advertising

  2. lazyadmin

    lazyadmin Guest

    Well I guess I answered myself :)

    http://www.learnasp.com/learn/uploadlimitsize.asp

    Rod
    http://www.thelazyadmin.com


    "lazyadmin" <> wrote in message
    news:%23wrXz%...
    >I would like to use this code on my website to allow simple file uploads
    >from clients. I would like to restrict the file types they can upload. Can
    >this be done? Any help appreciated.
    >
    > Rod
    > http://www.thelazyadmin.com
    >
    > ASP Code upload_file.asp
    >
    > <% @Language=VBScript %>
    > <HTML>
    > <HEAD>
    > <TITLE>FileUp Upload Simple Sample</TITLE>
    > </HEAD>
    > <BODY>
    > <%
    > Dim oFileUp
    > '--- Instantiate the FileUp object
    > Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
    > '--- Set the Path property to the location you wish to temporarily
    > cache the incoming file before saving
    > oFileUp.Path = Server.MapPath("uploads\data")
    > '--- Check if a file was selected (myFile is coming from the html
    > code)
    > '--- If so, continue processing
    > If Not oFileUp.Form("myFile").IsEmpty Then
    > '--- Save the file
    > oFileUp.Form("myFile").Save
    > '--- The file is saved, display a confirmation message
    > Response.Write ("<B>File saved successfully on the server
    > as:</B><BR>")
    > '--- The ServerName() property is the full path of the file where it
    > was saved on the server
    > Response.Write(oFileUp.Form("myFile").ServerName)
    > Else
    > Response.Write("Error: There was no file submitted for upload.")
    > End If
    > '--- Destroy objects
    > Set oFileUp = Nothing
    > %>
    >
    >
    > Webpage Code Upload_File_Form.html
    >
    > </BODY>
    > </HTML>
    > Sample Upload Form (upload_file_form.html)
    > <HTML>
    > <HEAD>
    > <TITLE>FileUp Simple Upload Sample</TITLE>
    > </HEAD>
    > <BODY>
    > <H3 ALIGN=center>&nbsp;</H3>
    > <H3 ALIGN=center>Asp FileUp Upload Sample</H3>
    > <p ALIGN=center>&nbsp;</p>
    > <FORM ACTION="fileUp.asp" ENCTYPE="MULTIPART/FORM-DATA"
    > METHOD="POST">
    > <TABLE WIDTH="100%">
    > <TR>
    > <TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>
    > <!--
    > Note: Notice this form element is of TYPE="FILE"
    > -->
    > <TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile" size="20"><BR>
    > Please click Browse to select a file.</TD>
    > </TR>
    > <TR>
    > <TD ALIGN="RIGHT">&nbsp;</TD>
    > <TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
    > </TR>
    > </TABLE>
    > </FORM>
    > </BODY>
    > </HTML>
    >
    lazyadmin, Jan 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vicky

    file upload size limit

    Vicky, Feb 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    506
    Eric Lawrence [MSFT]
    Feb 11, 2004
  2. Tom Kaminski [MVP]

    graceful file upload limit error?

    Tom Kaminski [MVP], Jul 19, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,721
    Shan Plourde
    Jul 20, 2004
  3. MS News \(MS ILM\)

    File upload limit handleing

    MS News \(MS ILM\), Aug 18, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    588
    MS News \(MS ILM\)
    Aug 20, 2004
  4. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,421
    Bruce Barker
    Aug 3, 2005
  5. Replies:
    1
    Views:
    1,066
    Victor Bazarov
    Jun 28, 2005
Loading...

Share This Page