XUpload - Do a verification before uploading a file

Message
Author
eduardoll
Posts: 2
Joined: May 11, 2009 2:01 pm

Do a verification before uploading a file

#1 Postby eduardoll » May 11, 2009 2:08 pm

Hi all,

I will add a form to the file upload. The file should be uploaded only if the verification on the form is valid.

Where can i insert this verification? I've already tried to insert it in "upload.cgi" after

Code: Select all

my $cg = new CGI;
if( $cg->cgi_error() )
{
   &DelData($temp_dir);
   &xmessage("ERROR: Maximum upload size exceeded");
}
but file is still being uploaded.. The error message appears right after the upload is complete..

Thanks!

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#2 Postby PilgrimX182 » May 11, 2009 3:25 pm

Actually the form fields become available only after complete upload.
Only can recommend JS validation on browser side before upload.

eduardoll
Posts: 2
Joined: May 11, 2009 2:01 pm

#3 Postby eduardoll » May 11, 2009 4:01 pm

But the validation I need to do is to check whether or not already exists a key in the server's database..

for example, form contains:
name:
date:
filename:

I need to check if a data with the key (name+date+filename) had already being inserted into the database..

Is it possible to do this server-side validation using java script? Could you point the directions i should follow?

Thanks!

User avatar
PilgrimX182
Posts: 2186
Joined: Mar 22, 2006 1:39 pm

#4 Postby PilgrimX182 » May 11, 2009 5:08 pm

Well if there are not many fields, then you can add these to form action URL, like I add random seed now in xupload.js directly before upload start. Check the code there, where I set up form action.

giorrrgio
Posts: 8
Joined: Aug 04, 2008 11:11 am

#5 Postby giorrrgio » May 12, 2009 10:01 am

Is it possible to do this server-side validation using java script
You could use an Ajax request (with Prototype, for example) just before executing the StartUpload function to test if the key exists, calling StartUpload and submitting the form only is validation is ok.
This is not so strong or secure, but works fine for most of the cases.
Another way (not tested) is to add custom fields as described in this thread:
http://www.sibsoft.net/forum/multiple-f ... -t793.html
and then validate inside the upload.cgi the way you guessed.