Print Page | Close Window

Uploading files: preventing double upload

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12316
Printed Date: 30 March 2026 at 11:02pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Uploading files: preventing double upload
Posted By: zaboss
Subject: Uploading files: preventing double upload
Date Posted: 26 October 2004 at 4:37am
I have a site where users must upload some files. Sometimes, durig the upload, some errors occurs. Although they are instructed not to do so, some users try again and again and again... (7 times was the maximum number of trys)...

Since the upload code is huge - about 2500 lines of code - it is quite difficult to creat an error handling (the code reads the file and inserts data it contain in a database).

Is there a way of grabbing the server response and if an error occur to redirect user to a page telling "There was an error, please send the file that created to the webmaster! And please, do not try to upload it again!"?

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web



Replies:
Posted By: Mart
Date Posted: 26 October 2004 at 5:07am

At very the top of the page put this

<% On error resume next %>

And at the bottom put this


<%

If err.Number > 0 Then

Response.redirect "error.html"

End If

On error goto 0

%>



Posted By: Mart
Date Posted: 26 October 2004 at 5:54am
p.s. you might want to set a cookie of there's an error and not allow the user to upload when the cookie is present


Posted By: zaboss
Date Posted: 26 October 2004 at 6:49am
< ="text/"> It doesn't work. It just skip the error and continues with the file, but is not redirecting to an error page....


-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: theSCIENTIST
Date Posted: 28 October 2004 at 12:29pm
The whole point of using (On Error Resume Next) is exactly that, as for the redirect to an error page, it lies with the code and how you are trapping/handling errors.

If your code is that big, you may have to seperate it to make it more manageable by using several files.

One more piece of advice, using a cookie to mark users that uploaded is good, but don't tell them, or they will just clear the cookies.

-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com


Posted By: Mart
Date Posted: 28 October 2004 at 12:46pm
You have to tell them really, you can't just have an error message saying "I don't want that file" when you try to upload a file... well you could, but you would get 100's of emails asking why you don't like my files


Posted By: Gullanian
Date Posted: 28 October 2004 at 12:48pm
2,500 lines seems rather excessive for uploading a file, you might want to look into ASPUpload, it has built in features for file duplication handling.


Posted By: zaboss
Date Posted: 28 October 2004 at 1:23pm
@TheScientis and Gullanian

The code is actually that big because I write the insertion statement  like this:

mSQL = "INSERT INTO tblAlteSituatii("
    mSQL = mSQL & "strOra,"
    mSQL = mSQL & "strSeenBy,"
    mSQL = mSQL & "strData,"
    mSQL = mSQL & "strDetalii,"
    mSQL = mSQL & "strSituatie)"

    mSQL = mSQL & "Values("
    mSQL = mSQL & "'" & Replace(thefields3(1),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(Session("UserName"),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(thefields3(2),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(thefields3(3),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(thefields3(4),"'","''") & "')"

'It executes the SQL
MyConn.Execute (mSQL)

And this is the smallest table...
The problem is not the double uploading in itself, I don't care about that, they are only small text files, but the fact that by uploading it, it will be processed twice or even more, so I end up with lots of duplicate records in the db...
That's why (this @ Mart) the error message it's OK saying "There was an error processing the file, the webmaster has been inform about it. You DON'T NEED TO UPLOAD IT AGAIN!!!"



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: dpyers
Date Posted: 28 October 2004 at 2:07pm
If you want to avoid having the file recreated, why not just check if it exists?

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

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net