Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  SA: File Upload, Multi-part form
     [next Lesson]  SA: File Upload, Many Files

Limiting the Upload Size

SA-FileUp's MaxBytes property allows you to limit the size of files uploaded to your server. If MaxBytes is set, SA-FileUp will stop writing to the hard disk when the value of MaxBytes is reached. For example, if MaxBytes = 1000, only 1000KB of a 100,000KB file will be written to the server hard disk.

Set MaxBytes once and it will apply to all files in the current upload, limiting each of them to the value that you specify.

Using MaxBytes, you can prevent malicious users from filling your web server's hard disk.

   filename=/sa/test/limitsizerespond.asp

<Test Script Below>



    <html>
    <head>
    <title>Limit File Size</title>
    </head>
    <body>
    Thank you for uploading your file.<br>
    <% Set upl = Server.CreateObject(SoftArtisans.FileUp) %>
    <% upl.MaxBytes = 1000 '--- limit the upload size to 1000 bytes %>
    The maximum file size that you are permitted to upload is <%=upl.MaxBytes%> bytes.<br>
    <% upl.SaveAs C:\temp\upload.out %>
    Total Bytes Written: <%=upl.TotalBytes%><br>
    Server File Name: <%=upl.ServerName%><br>
    Total Bytes Transmitted: <%=Request.TotalBytes%>
    </body>
    </html>

Restricting File Types

Use SA-FileUp's ContentType property and a Select condition to save only files of a specific type.

   filename=/sa/test/limittyperespond.asp

<Test Script Below>


<html>
<head>
<title>Limit File Type</title>
</head>
<body>
    <% Set upl = Server.CreateObject("SoftArtisans.FileUp") 

    '--- Parse out the file name
    FName = Mid(upl.UserFilename, InstrRev(upl.UserFilename, \) + 1)

    '--- Retrieve the file's content type and assign it to a variable
    FCONT = upl.ContentType

    '--- Restrict the file types saved using a Select condition
    Select Case LCase(FCONT) 
    Case "image/gif"
        upl.Save 
        Response.Write <P> & FName &  has been saved.
    
    Case image/pjpeg 
        upl.Save 
        Response.Write <P> & FName &  has been saved.
    
    Case Else
        upl.delete
        Response.Write  <P> & You may only upload gif and jpeg files.<BR>
        Response.End 
    End Select

    %>
</body>
</html>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site