Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^3: Upload hook syntax and locationby shenme (Priest) |
on Dec 29, 2004 at 05:03 UTC ( [id://417921]=note: print w/replies, xml ) | Need Help?? |
Some of the other nodes I referenced above give more background information.
The problem is indeed that once you call CGI->new() you are 'trapped' until CGI.pm has processed _all_ the form data including uploaded files. But CGI.pm has added this optional 'hook' feature that allows you to specify one of your routines for CGI.pm to call _during_ the processing of the form data. You call CGI.pm and it runs until done, but each time it processes some more upload data it calls your routine. In your code you could do something like this: (untested) Somewhere else in your same code you define your routine that CGI.pm will call for each chunk of data. Here we rely on that extra parameter value that CGI.pm copies from the new() call to pass into your routine. We open the file, give the filehandle to CGI.pm, and CGI.pm adds that to every call to your routine: CGI.pm will call this routine many times, once for each chunk of the upload data it processes, something like: (in CGI.pm) Note that value $ENV{CONTENT_LENGTH} will really be larger than the uploaded file sizes, as it includes the rest of the form data also, but it's close and the only 'total' number we have (sigh). Your display CGI could be as simple as:
Now this example used files (I'm currently using a database table). You might want to use file locking (see flock in perlfunc and do SuperSearch's) to make sure the display CGI doesn't read a partially written record, though with one line it seems unlikely. Anyway, I hope this helps, and that I haven't confused you more than before.
In Section
Seekers of Perl Wisdom
|
|