On Wed, Aug 01, 2007 at 08:58:58AM -0700, Michael Reece wrote:
> 
> On Aug 1, 2007, at 8:31 AM, Amiri Barksdale wrote:
> 
> >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?
> 
> you are correct, it would typically not skip that field, since you  
> expect all fields to be numbered, assuming your javascript is working  
> correctly and your users don't try anything malicious.
> 
> but since the code below the next relies on it having a successful  
> $id to use as a key for the hash, i find it wise to test for such  
> assumptions just in case something goes awry.

Here's how I handle multiple file uploads with mason 1.3 on apache2 with
libapreq2:


In my HTML I have a loop for the number of file uploads and then:

<td><input name="attachment_<% $ordernumber %>" type="file" id="file1" 
size="25"></td>

Then in my %init something like this:

use Apache2::Upload;
my $req = Apache2::Request->new($r);
my @uploads = $req->upload;
 foreach my $uploadname ( @uploads ) {
   my $upload = $req->upload($uploadname);
   # skip empty ones
   next if ( not $upload->name );
   next if ( $upload->filename eq "" );

   # get the id we're dealing with
   $upload->name =~ m/attachment_(\d+)$/;
   my $attachment_order = $1;

   # massage filename
   my ($filenametrimmed) = $upload->filename =~ m!([^/\\]*$)!;
   my $filenameshort = "/user_files/$filenametrimmed";
   my $savefilename = $base_path . $filenameshort;

   # this deals with reading the file from the $upload->fd, saving it to
   # the $savefilename path, etc.
   my $ret = $m->comp("/components/fileupload.mc", upload => $upload, 
savefilename => $savefilename );
       
   # error handling for return value from component
   # anything else that's needed after the file has been uploaded, in my
   # case boring stuff like putting the file into a database and
   # spitting out "blah balh uploaded" to the screen.
}


Hopefully that gives you a bit of an idea... it's a bit ugly I'm sure,
but works for me.  I've actually moved to using a hacked version of a
file progress upload freeware I found somewhere due to client
requirements for large uploaded files, but the above was my pure mason
solution.

-- 
Alan <[EMAIL PROTECTED]> - http://arcterex.net
--------------------------------------------------------------------
"Beware of computer programmers that carry screwdrivers." -- Unknown

-------------------------------------------------------------------------
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