Full marks to the other posts, but the advice about using "Content-Disposition" headers neglects Netscape 4.x browsers (at least in my experience). To get around this difference in browsers, I have used the following snippet of code, with credit going to Merlyn's web techniques column for the path-info-in-query-string trick:
# determine the http header to send the browser client:
my $user_agent = $q->user_agent; # CGI query object
if ($user_agent =~ m/MSIE/i) { # for IE users, the following wo
+rks:
print "Content-Disposition: attachment; filename = $name\n\n";
}
else { # for Netscape clients, need to
+do a 2-pass trick here...
if ($q->path_info() ) {
# 2nd pass: collect the extra path info which Netscape client
# will use to name the downloaded file:
print $q->header('application/x-octet-stream');
}
else {
# 1st pass: add the name info to the http header path info var
# and redirect back upon itself for the 2nd pass:
$q->path_info("/$name");
print $q->redirect($q->self_url());
exit;
}
}
Hope this helps ..Guv
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|