here's a demo showing the script executing before the client is through uploading it, this is a proof from an uncertainty we arrived at in the chatterbox with [id://bart]
#!/usr/bin/perl $|++; use strict; use warnings; use lib './lib'; use CGI; print STDERR "Here we are\n\n"; unless( $ENV{REQUEST_METHOD} eq 'POST' ) { #show the itty bitty upload form: my $cgi = new CGI; print $cgi->header() . qq{ Using CGI v.$CGI::VERSION<br> <form action="file_upload" method="post" enctype="multipart/form +-data"> <input type="hidden" name="test" value="value"> <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? ## print <STDIN>;exit; #peek for wisdom 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} ) { ## my $somevar = $cgi->param('somevar'); #ERROR! #Can't call method "param" on an undefined value warn "Getting an upload for $filename"; $uploads{$filename} = 1; } warn $bytes_read if $buffer; ## print $buffer if $buffer; #back at ya! } }
[download]