From: James M. <jm...@tr...> - 2003-02-01 00:23:47
|
Hi, As a follow up to a question I asked and hackishly solved a few years ago about uploading a file, I am planning on using $form->{'query_apache'}, in order to upload files. Can I rely on this element to remain in getCurrentForm? Otherwise I will need to split off an instance of apache::request prior to calling createenvironment, but even then, according to the Apache::Request documentation, it isn't so safe to parse a file with an instance. Anyway, example code follows (different from the similar code in Admin.pl). ... my $form = getCurrentForm(); my $apr = $form->{'query_apache'}; my $upload = $apr->upload; my $loaded; if($upload){ $loaded = { type => $upload->type, name => $upload->name, filename => $upload->filename, fh => $upload->fh, size => $upload->size, }; #debug # print Dumper($loaded); my $filename = $loaded->{'filename'}; local *BLOB; if (! (-d "temp") ){ if (! (mkdir("temp",0744) )) { carp ("can't make temp \n"); } } if( -e "temp/$filename" ){ unlink "temp/$filename"; } $upload->link("temp/$filename") or die sprintf "link from '%s' failed: $!", $upload->tempname; # prove it works by echoing if($loaded->{'type'} =~ /text/){ print "<BR><CODE>"; open(BLOB, "<temp/$filename"); while (<BLOB>) { print "$_ <BR>"; } close BLOB; print "</CODE>"; } elsif ( $loaded->{'type'} =~ /image/){ print "<BR><img src='http:$constants->{'rootdir'}/temp/$filename'>"; } # other handlers as needed. } -- James E. Marca |