[PHP] force download with header()

2002-12-08 Thread Patrick McKinley
i was reading about php.net looking for a way to force a download of a txt file, 
rather than the browser displaying the file.
i ran into header() that seems to be able to accomplish it... but seeing as i'm very 
much a newbie at php, i can't seem to make this work
if the file i want to download is
nfo/60/ind.txt

how would i impliment this:
?php
// We'll be outputting a PDF
header(Content-type: application/pdf);

// It will be called downloaded.pdf
header(Content-Disposition: attachment; filename=downloaded.pdf);

// The PDF source is in original.pdf
readfile('original.pdf');
?




Re: [PHP] force download with header()

2002-12-08 Thread Marco Tabini
Are you using Internet Explorer? Then it's a feature of IE--it ignores
the disposition headers sent by your server because its registry tells
it that PDF files must be viewed inline. There's a way around it,
although it's a bit kludgy--I wrote a small article about it that you
can find here (it's in PDF format, as well): 

http://www.phparch.com/issuedata/2002/december/sample.php

Essentially, you're telling IE to download a file with the extension
.pdf  (not the space) so that it can't match the MIME type anymore and
will follow your suggestion of downloading the file instead of
displaying it inline.

Hope this helps!

Cheers,


Marco
-- 

php|architect - The Magazine for PHP Professionals
The monthly magazine dedicated to the world of PHP programming

Check us out on the web at http://www.phparch.com!

---BeginMessage---
i was reading about php.net looking for a way to force a download of a txt file, 
rather than the browser displaying the file.
i ran into header() that seems to be able to accomplish it... but seeing as i'm very 
much a newbie at php, i can't seem to make this work
if the file i want to download is
nfo/60/ind.txt

how would i impliment this:
?php
// We'll be outputting a PDF
header(Content-type: application/pdf);

// It will be called downloaded.pdf
header(Content-Disposition: attachment; filename=downloaded.pdf);

// The PDF source is in original.pdf
readfile('original.pdf');
?


---End Message---
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php