qbxk has asked for the wisdom of the Perl Monks concerning the following question:
now you may say "well, you don't even need the $cgi variable in your hook!" and i'll tell you that i do, this is only a demo. ;) specifically, if i could have access to the form name that contained the file the hook is currently running against, i'd be happy. (in this case that would be "myFile")#!/usr/bin/perl $|++; use strict; use warnings; use CGI; unless( $ENV{REQUEST_METHOD} eq 'POST' ) { #show the itty bitty upload form: my $cgi = new CGI; print $cgi->header() . qq{ <form action="file_upload" method="post" enctype="multipart/form +-data"> <input type="file" name="myFile"> <input type=submit> </form> }; } else { print "Content-Type: text/plain\n\n"; # [sic] can't use CGI yet, 'me +mber? sub hook; my $cgi = new CGI( \&hook, undef, 0 ); #use the hook, and don't use a tempfile, i'll handle that myself, #don't pass any "data" to hook either, what would i pass? my %uploads; sub hook { my ($filename, $buffer, $bytes_read, $data) = @_; my $fh; unless( exists $uploads{$filename} ) { #oh yeah, and $filename might not be unique either, but what other cho +ice do i have?! this condition tells me that it's our first time on t +his file my $somevar = $cgi->param('somevar'); #ERROR! #Can't call method "param" on an undefined value warn "Getting an upload for $filename"; $uploads{$filename} = 1; } print $buffer if $buffer; #back at ya! } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cgi and upload_hook
by TedPride (Priest) on May 22, 2006 at 10:12 UTC | |
|
Re: cgi and upload_hook
by Miguel (Friar) on May 22, 2006 at 12:34 UTC | |
by qbxk (Friar) on May 22, 2006 at 18:02 UTC | |
by Miguel (Friar) on May 22, 2006 at 23:41 UTC | |
by qbxk (Friar) on May 24, 2006 at 00:49 UTC | |
|
Re: cgi and upload_hook
by jdtoronto (Prior) on May 22, 2006 at 15:32 UTC | |
by Miguel (Friar) on May 22, 2006 at 17:01 UTC | |
|
Re: cgi and upload_hook
by daitau (Beadle) on May 26, 2006 at 08:25 UTC | |
by qbxk (Friar) on May 26, 2006 at 10:28 UTC |