| Author |
Topic Search Topic Options
|
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Topic: Uploading files: preventing double upload 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!"?
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
%>
|
Edited by Mart
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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....
|
|
|
 |
theSCIENTIST
Senior Member
Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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!!!"
|
|
|
 |