Solved

Upload file size validation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now