Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Upload file size validation

Posted on 2010-11-23
4
Medium Priority
?
758 Views
Last Modified: 2012-06-21
Experts,

I have a web form on an intranet site which allows internal users to upload documents and send them as attachments via email. I'm using classic ASP to attain this task. When the user completes the form, the files get uploaded to the server, sent to the user via email, and deleted right away from the server.

I want to validate the size of these files to be uploaded. I realize that this cannot be done using JScript. I've used the getSize() function (see code below) but in vain. Neither IE nor Chrome respond to this code and FF throws "ActiveXObject is not defined" error.

I've also tried using the server side validation and it doesn't work either (code attached below).

Please let me know what other options I can opt for. I'd appreciate any help.

Thanks,
<script type="text/vbscript" language="vbscript">
function getSize(){

    	var myFSO = new ActiveXObject("Scripting.FileSystemObject");
		var filepath = document.frmSend.attach1.value;
		var thefile = myFSO.getFile(filepath);
		var size = thefile.size;
		alert(size + " bytes");
}    



------------------------------------------------------------

<%
Set Upload = Server.CreateObject("Persits.Upload")
' Limit file size to 50000 bytes, throw an exception if file is larger
Upload.SetMaxSize 50000, True

' Intercept all exceptions to display user-friendly error
On Error Resume Next

' Perform upload
Upload.Save "c:\upload"

' 8 is the number of "File too large" exception
If Err.Number = 8 Then
   Response.Write "Your file is too large. Please try again."
Else
   If Err <> 0 Then
      Response.Write "An error occurred: " & Err.Description
   Else
      Response.Write "Success!"
   End If
End If
%>
</script>

Open in new window

0
Comment
Question by:SasDev
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 34196903
Is any part of this being stored on the db?

You could easily ascertain the size from there.
0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 2000 total points
ID: 34197009
How about this?

<%
Set Upload = Server.CreateObject("Persits.Upload")
' Limit file size to 50000 bytes, throw an exception if file is larger
Upload.SetMaxSize 50000, True

' Intercept all exceptions to display user-friendly error
On Error Resume Next

' Perform upload
Upload.Save "c:\upload"

%>
Files Size<BR>
<%
For Each File in Upload.Files
Response.Write File.Name & "= " & File.Path & " (" & File.Size &" bytes)<BR>"
Next
%>

<P>


' 8 is the number of "File too large" exception
If Err.Number = 8 Then
   Response.Write "Your file is too large. Please try again."
Else
   If Err <> 0 Then
      Response.Write "An error occurred: " & Err.Description
   Else
      Response.Write "Success!"
   End If
End If
%>

Open in new window


This is from Persits site:

http://www.aspupload.com/manual_simple.html
0
 
LVL 1

Assisted Solution

by:SasDev
SasDev earned 0 total points
ID: 34230366
Sorry for not responding to your posts.

Your posts were helpful and the link you provided was of a good help too.

Although I found the resolution to my query on this link: http://www.webmaster-talk.com/asp-forum/110314-how-can-i-add-file-size.html

I appreciate your help.

Thanks
0
 
LVL 1

Author Closing Comment

by:SasDev
ID: 34272717
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question