Thanks Michael! I appreciate your response.

Can you possibly tell me what you mean with the "next unless" statement? It
seems to say go to the next upload object, i.e., the next file, unless this
one is numbered? But most of them will be numbered, so it won't go... to the
next one?

I am a straight-up amateur as you can probably tell from what I posted--do
you know of any resources where I can learn about how to do these nested
loops?

Amiri

On 7/31/07, Michael Reece <[EMAIL PROTECTED]> wrote:
>
> can't you pass a field name to $r->upload()?
>
>      my $upload = $r->upload($thash{file});
>      $thash{filename} = $upload->filename;
>      $thash{fh} = $upload->fh;
>
>
> or, from the other perspective, using $r for the outer loop:
>
>      foreach my $upload ( $r->upload ) {
>          next unless $upload->name =~ m{^file-(\d+)$};     # Must
> match attach.n or it's not mine!
>         my $id = $1;
>
>         $thash{$id} = { filename => $upload->filename, fh => $upload->fh
> };
>
>          foreach my $attr ( grep /-\d+$/, keys %ARGS ) {
>              my ($key) = $attr =~ /^(.*)-\d+$/;
>              # validate $key if desired..
>              $thash{$key} = $ARGS{$attr};
>          }
>      }
>
>
> On Jul 31, 2007, at 9:23 AM, Amiri Barksdale wrote:
>
> > Multiple File Uploads: $r or %ARGS?
> >
> > Hey folks. I'm new here, and this is my first post.
> >
> > I'm trying to figure out a way to manage multiple file uploads. I
> > have a form that allows users to upload arbitrary numbers of files,
> > which I then need to process and save on the server. I have a
> > javascript that allows this arbitrary number of files: by clicking a
> > link, you create a new form field that adds a numeral to the end of
> > the field name. The %ARGS hash looks like this for a single file:
> >
> > file => 273141
> > title => Back to
> > id => 7
> > number => 1
> > creation_date => 2007
> >
> > A multiple upload %ARGS looks like this:
> >
> > file => 273141
> > title => Back to
> > id => 7
> > number => 1
> > creation_date => 2007
> >
> > file-2 => that'shot8
> > title-2 => Natural
> > id-2 => 6
> > number-2 => 2
> > creation_date-2 => 1985
> >
> > file-3 => Introduction
> > title-3 => Stuff Like This
> > id-3 => 12
> > number-3 => 3
> > creation_date-3 => 1998
> >
> > I created a loop that allows me to handle the %ARGS data:
> >
> >          my $i = 2;
> >
> >          while ( $i <= $ARGS{'numberfiles'} ) {
> >
> >              my %thash;
> >
> >
> >              foreach my $key ( sort( keys %ARGS ) ) {
> >                  if ( $key =~ /creation_date-$i/ ) {
> >                      $thash{'creation_date'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /title-$i/ ) {
> >                  $thash{'title'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /number-$i/ ) {
> >                      $thash{'number'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /rate-$i/ ) {
> >                      $thash{'rate'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /type-$i/ ) {
> >                  $thash{'type'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /id-$i/ ) {
> >                      $thash{'id'} = $ARGS{$key};
> >                  }
> >                  if ( $key =~ /file-$i/ ) {
> >                  $thash{'file'} = $ARGS{$key};
> >                  }
> >              }
> >
> >              my $nfile = $api->newBean('file');
> >         }
> >     $nfile->save($api);
> >     $i++;
> > }
> >
> > But the problem is handling the actual files simultaneous with this
> > file information. I have been trying to construct some sort of loop
> > to go through each $r->upload->tempname object, but it seems like the
> > only way to do that is to make it an entirely separate loop. Which
> > gets kludgier and kludgier, because my object-oriented perl requires
> > that I make a "mini hash" out of every file uploaded--the %thash
> > above. I know there has to be an elegant way to do this: I just don't
> > know it.
> >
> > Is it possible to use the Apache::Request object instead of %ARGS
> > altogether? Could I handle the file data and the files together using
> > $r instead of taking the info from %ARGS here and trying to take the
> > data from $r there?
> >
> > Has anyone been faced with this problem before? All comments and
> > help, insights and wisdom, would be greatly appreciated.
> >
> > Amiri
>
> ---
> michael reece :: software engineer :: [EMAIL PROTECTED]
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to