Force Download
Moderator: General Moderators
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
Force Download
Without using the header() function, how else can I force a download?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Force Download
I'm wondering why you ask, but maybe the <meta http-equiv=" ... " ... /> tags will do it. Sounds like wonky design to me thoughSidewinderX wrote:Without using the header() function, how else can I force a download?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
Re: Force Download
Well I've made a download component for Joomla! and it is giving me a heck of a time with the download of pdf files (only pdf files). I checked php.net and there is a bunch of problems with using headers to download pdf's with IE and other stuff but my code works fine when its not integrated into Joomla! If I use something as simple as this in Joomla it does not work, but using it stand-alone it works fine.d11wtq wrote:I'm wondering why you ask
Code: Select all
<?php
$file = "http://www.irs.gov/pub/irs-pdf/fw4.pdf";
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename="".basename($file).""");
readfile("$file");
?>- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
What "does not work" ? Joomla probably already sent output to the browser at the time you tried to send headers.
BTW, I'm also aware of IE's issues with dynamically generated PDF's (and other content). It only crops up when running over SSL with the no-cache header set. A straight redirect to a temporary file on disk will fix that
BTW, I'm also aware of IE's issues with dynamically generated PDF's (and other content). It only crops up when running over SSL with the no-cache header set. A straight redirect to a temporary file on disk will fix that
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
When you download the pdf file when it is integrated into Joomla it says it says the file is corrupt (dont know the exact message off the top). If you download the file 10 times, at least 5 of the files will have differing file sizes.
But using the script above not integrated will download the file properly every time
But using the script above not integrated will download the file properly every time
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Make sure you exit() after the PDF has been output. If You don't, Joomla will continue to display it's own output which will inadvertently finish up at the bototm of the PDF document, thus corrupting it.SidewinderX wrote:When you download the pdf file when it is integrated into Joomla it says it says the file is corrupt (dont know the exact message off the top). If you download the file 10 times, at least 5 of the files will have differing file sizes.
But using the script above not integrated will download the file properly every time
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
In case this crops up, it is my experience that this error on IE is not just for PDF's, but almost all generated files (Office files, CSV, TXT). I experienced this recently and had to adjust all cache-control settings that involved no-cache (cache-control and pragma). I know it is not entirely related to this topic, but it is still handy to know.d11wtq wrote:BTW, I'm also aware of IE's issues with dynamically generated PDF's (and other content). It only crops up when running over SSL with the no-cache header set. A straight redirect to a temporary file on disk will fix that
d11wtq | Agreed, it is all dynamically created content that is uncached which causes the fault