On Wed, Jan 02, 2008 at 11:45:33AM -0600, Kenneth A Graves wrote:
> On Wed, 2008-01-02 at 12:38 -0500, Xiong, Bob wrote:
> > Thanks, John. But I was looking for the Perl code. I also intended to allow 
> > a
> > user to download the file and save it to his/her own computer (without 
> > opening
> > it up). Sorry about not making myself clear. - Bob Xiong
> 
> The trick is to lie to the browser about the content-type.
> E.g., for a PDF file if you use
>       print $cgi->header('application/pdf");
> then the browser knows it has PDF data, and will use the correct plugin
> or helper application to display it.
> On the other hand, if you claim
>       print $cgi->header('application/octet-stream');
> then the browser has no information about what plugin or helper app to
> use, so will usually pop up the "select application or save file to
> disk" dialog.  *This is browser-dependent.*  The browser can cheat and
> look at file extensions, or the first few bytes of the file data.  But
> it works most of the time.

I don't think this is the best solution. Instead, one should probably
set the "Content-Disposition: attachment;
filename=preferred_filename.pdf" . This will tell the browser "Download
ths file to the filename specified" -- which  the browser will then
present to the user with that filename as the default, and ask them
where to save it, at least in lynx, Firefox, IE6/7, Safari, and Opera. 

Regards,
-- 
Christopher Schmidt
Web Developer
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to