[prev in list] [next in list] [prev in thread] [next in thread]
List: slashcode-development
Subject: [Slashcode-development] $form->{'query_apache'}
From: James Marca <jmarca () translab ! its ! uci ! edu>
Date: 2003-02-01 0:22:44
[Download RAW message or body]
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
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Slashcode-development mailing list
Slashcode-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/slashcode-development
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic