Solved

Upload file size validation

Posted on 2010-11-23
4
750 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 28

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 28

Accepted Solution

by:
sammySeltzer earned 500 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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