XUpload - Name Value pair format in post

Message
Author
bkerns
Posts: 2
Joined: Feb 25, 2009 2:21 am

Name Value pair format in post

#1 Postby bkerns » Feb 25, 2009 5:08 am

I am using 3.0 pro and trying to modify the post format so that I get the field_name in name for file_name & file_name_orig.

How do I modify this code:

Code: Select all

### Sending data with POST request if need
my $url_post = $c->{url_post} || $ENV{HTTP_REFERER};
if($url_post)
{
   if($url_post=~/\.htm(l|)$/i)
   {
      print"Content-type: text/html\n\n";
      print"<HTML><HEAD><Script>parent.document.location='$url_post'</Script></HEAD></HTML>";
      exit;
   }
   if($ENV{QUERY_STRING}!~/js_on=1/)
   {
     $url_post.='?';
     $url_post.="\&$_->{name}=$_->{value}" for @har;
     print $cg->redirect( $url_post );
     exit;
   }
   print"Content-type: text/html\n\n";
   print"<HTML><BODY><Form name='F1' action='$url_post' target='_parent' method='POST'>";
   for my $f (@files)
   {
       my @file_fields = qw(field_name file_name file_name_orig);
       print"<textarea name='$_'>$f->{$_}</textarea>" for @file_fields;
   }
   print"<textarea name='$_->{name}'>$_->{value}</textarea>" for @har;
   print"</Form><Script>document.location='javascript:false';document.F1.submit();</Script></BODY></HTML>";
   exit;
}

print"Content-type: text/html\n\n";
print"Upload complete.";

exit;
So that instead of getting name value pairs like:

Code: Select all

name="field_name" value="file_0"
name="file_name" value="about_filming2.jpg"
name="file_name_orig" value="about_filming.jpg"
name="field_name" value="file_1"
name="file_name" value="about_rental2.jpg"
name="file_name_orig" value="about_rental.jpg"
name="field_name" value="file_2"
name="file_name" value="ahmanson6.jpg"
name="file_name_orig" value="ahmanson.jpg"
...I get name value pairs like:

Code: Select all

name="file_0_field_name" value="file_0"
name="file_0_file_name" value="about_filming2.jpg"
name="file_0_file_name_orig" value="about_filming.jpg"
name="file_1_field_name" value="file_1"
name="file_1_file_name" value="about_rental2.jpg"
name="file_1_file_name_orig" value="about_rental.jpg"
name="file_2_field_name" value="file_2"
name="file_2_file_name" value="ahmanson6.jpg"
name="file_2_file_name_orig" value="ahmanson.jpg"
Somehow I think the change need to be made where it loops through each of the files at the notorious line 409 of the above "sending data with POST request" section. I can't figure out how to add the field_name's value to each of the other field's names for a submitted file.

Any help is greatly appreciated.
-Brian

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

#2 Postby PilgrimX182 » Feb 26, 2009 12:17 pm

Replace

Code: Select all

   for my $f (@files)
   {
       my @file_fields = qw(file_name file_name_orig file_status file_size file_descr file_mime);
       print"<textarea name='$_\[]'>$f->{$_}</textarea>" for @file_fields;
   }
with

Code: Select all

   for my $f (@files)
   {
       my @file_fields = qw(file_name file_name_orig file_status file_size file_descr file_mime);
       print"<textarea name='$f->{field_name}_$_'>$f->{$_}</textarea>" for @file_fields;
   }

bkerns
Posts: 2
Joined: Feb 25, 2009 2:21 am

Name Value pair format in post

#3 Postby bkerns » Feb 26, 2009 4:15 pm

Perfect!

Thanks.

-Brian