Solved

Upload file size validation

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

13 Experts available now in Live!

Get 1:1 Help Now