Steve,
I believe the best way would be to redirect the user to a page which has its
headers set to the appropriate MIME type. In a simple (non-C::A) CGI, you can
use the following line...
[ generate your file ]
print header(-type => "text/comma-separated-values",
-attachment => "download.csv");
Then print the data to the browser.
For PDFs and ZIPs, I'm not sure if you can simply print, but let us know if
you succeed. Also, there are semi-mature PHP resources which work with
generated PDFs.
- JC
Steve Hay <suppressed> wrote:
> Hi,
>
> I'm trying to figure out a good way to download dynamically generated
> files (mainly PDF files and ZIP files) using CGI-Application.
>
> The user directs his browser at a CGI script, rather than a static PDF
> file or ZIP file, and that script generates the file in question based
> on various input variables and then downloads it to the client.
>
> At the moment, the only way I can see to do this with CGI-Application is
> to read the whole generated file into a scalar variable, and return (a
> reference to) that from the run-mode. This is highly undesirable since
> the files in question could be very large.
>
> What I think I want is for CGI-Application to support run-modes
> returning some kind of valid filehandle (GLOB reference or IO::Handle).
> CGI::Application->run() would then read (in small chunks at a time) data
> from the returned filehandle and output it. The attached patch (against
> version 3.1) is a quick stab at this. It would need polishing up, but
> basically works OK as a demonstration of what I'm after.
>
> The following simple module (together with the obvious CGI script) shows
> it in action (albeit on a static file, rather than a dynamically
> generated one):
>
> ==========
> package MyDownloader;
> use CGI::Application;
> our @ISA = qw(CGI::Application);
>
> sub setup {
> my $self = shift;
> $self->run_modes(['download']);
> $self->start_mode('download');
> }
>
> sub download {
> my $self = shift;
> my $type = 'image/gif';
> my $file = 'C:\\Temp\\downloadee.gif';
> $self->header_props(-type => $type);
> open FH, $file;
> return \*FH;
> }
>
> 1;
> ==========
>
> What are your thoughts on this?
>
> Or is there a better way to do what I'm trying to achieve here?
>
> Cheers,
> - Steve
>
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.