The previous example showed how to upload multiple files and access each of their individual properties. Previously we've seen how to read properties of the file, such as the TotalBytes of the upload.
There are several properties that can be set. One very useful property is called MaxBytes. MaxBytes allows you to set a firm limit on the size of the uploaded file, ensuring that malicious users do not fill up your server's hard disk with huge files.
When you set the MaxBytes property (before saving the file!), SA-FileUp will write up to the number you specify and then stop. Any additional data will be discarded. You can set MaxBytes once and it will apply to all files in the current upload, limiting each of them to the value that you specify.
The maximum file size that SA-FileUp can process is 2 GB. If set MaxBytes equal to zero (0), SA-FileUp will revert to the default maximum, which is 2 GB.
Time for an example. We'll use the same simple form as in the very first upload:
<HTML> <HEAD> <TITLE>Please Upload Your File</TITLE> </HEAD> <BODY> <form enctype="multipart/form-data" method="post" action="formrespmax.asp"> Enter a big file to upload: <input type="file" name="f1"><br> <input type="submit"> </form> </BODY> </HTML>
Here would be the file 'formrespmax.asp'
<%@ LANGUAGE="VBSCRIPT" %>
<HTML><HEAD>
<TITLE>Upload File Results</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 size that you are permitted to upload is <%=upl.MaxBytes%> bytes per file.<br>
<% upl.SaveAs "C:\temp\upload.out" %>
Total Bytes Written: <%=upl.TotalBytes%><br>
Server Filename: <%=upl.ServerName%><br>
Total Bytes Transmitted by you: <%=Request.TotalBytes%>
</BODY>
</HTML>
Let's look at the form's processing (formrespmax.asp).
First, the MaxBytes:
<% upl.MaxBytes = 1000 '--- limit the upload size to 1000 bytes %> The maximum size that you are permitted to upload is <%=upl.MaxBytes%> bytes per file.<br>
We are setting MaxBytes as a limit for all files in this upload, even if there is more than one.
MaxBytes is Read/Write property, meaning that it is possible to both set its value and retrieve its value.
If you uploaded a file larger than 1000 bytes, you will have noticed that only the first 1000 bytes were written to disk.
We also added a new property called ServerName. ServerName is the name of file as it is stored on the web server, including the full path.
Server Filename: <%=upl.ServerName%><br>
And finally we displayed an ASP intrinsic property that displays the precise total number of bytes transmitted by the browser.
Total Bytes Transmitted by you: <%=Request.TotalBytes%>
You may have noticed that the total bytes transmitted by you is larger than your original file's size on disk. This is normal, since the browser must add information such as headers and encoding information. Request.TotalBytes reports the total including the file, encoding information and other form elements that may be present.
That completes our tutorial for now. Please see our many code samples for other examples of SA-FileUp functionality, including:
Thank you for using SA-FileUp!