Ang Mga Monks!
I raped
this code from
BBQ to solve
this problem (with thanks to
Skeeve,
benn and
fglock; and yes, dear
Skeeve, I learned a whole lot in the process!) I'm still a tried and true newbie for sure, but
this was a great learning exercise (with one of the best lessons being
How To RTFM. And like all good learning exercises (
pmdev, I need a spell checker here!) it's left me with insite into great new things that I should learn. So I've been looking through the POD for
CGI and can't find an answer to this question:
This code will send a generated file STDOUT:
# code ripped from perlmonks.org/index.pl?node_id=9277
chdir($filepath) || die "Unable to chdir to filepath";
my $filesize = -s $filename;
# print full header
print "Content-disposition: attatchment; filename=$filename\n";
print "Content-Length: $filesize\n";
print "Content-Type: application/x-tar\n\n";
# open in binmode
open(READ,$filename) || die;
binmode READ;
# stream it out
binmode STDOUT;
while (<READ>) { print; }
close(READ);
The following code will print an HTML "just in case" page:
my $q = CGI -> new();
print $q -> header( "text/html" ),
$q -> start_html (-title => "File Download",
-bgcolor => "#ffffcc" ),
$q -> p ( "If the file does not begin to dowload automatically i
+t can be downloaded <a href=\"$filepath$filename\">here</a>." ),
$q -> p ( "<a href=../foo.html>Back to foo</a>"),
$q -> p ( "<a href=../index.html>Bar Home</a>"),
$q -> end_html;
So the question finally is: How can a script be written to send a file and print an HTML page (or vice versa), or more basically, can a single script send two types of
Content-Types or
headers?
Cheers!
-p
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
-Howard Aiken
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.