Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: CGI hook

by rhesa (Vicar)
on Aug 08, 2006 at 02:05 UTC ( [id://566046]=note: print w/replies, xml ) Need Help??


in reply to CGI hook

Have a look at Apache2::UploadProgress.

Update: the upload hook that you pass into new() only takes effect on file uploads, not on generic POST requests.

Here's a little script that lets you test it. You will soon notice that the upload hook - while working as intended - is completely useless. The reason for this is that under regular CGI, you simply don't get to send output to the browser before the entire post has been received. To give feedback while the upload is in progress, you must trick the webserver into letting you, and that's why Apache2::UploadProgress is a much better tool than rolling your own.

use strict; use warnings; use CGI; my $hook_called; my $cgi = CGI->new( \&_hook ); print $cgi->header(), $cgi->start_html("FOO"), $cgi->start_multipart_form, $cgi->filefield('file'), $cgi->submit, $cgi->end_form; sub _hook { my ( $filename, $buffer, $bytes_read, $data ) = @_; if( !$hook_called ) { print "Content-Type: text/html; charset=ISO-8859-1\n\n"; # +$cgi is not defined here $hook_called = 1; } else { print "Read $bytes_read bytes of filename\n"; } $hook_called += $bytes_read; } print $cgi->end_html;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://566046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2025-01-14 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (42 votes). Check out past polls.