I am trying to create a download channel which should make it easier for users to publish their downloads.
To load a download, i use this template:
{exp:channel:entries channel="downloads" limit="1" dynamic="no" url_title="{segment_3}"}
<?php
if("{download_icon}"=="Pdf")
{
$file = "{download_file}";
$file = str_replace("{site_url}","",$file);
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename="{title}.pdf"');
readfile($file);
}
?>
{/exp:channel:entries}This forces the download to really download (not open in a buggy window). It also enables you to track the download with GoogleAnalytics.
Currently it only works for PDF files, i still have to include other headers.
My problem is that i cannot control the headers unless I hack a “Custom” template type into the template designer. This custom type is not recognized by the output class, in that way no headers are published (and i can publish them in my template).
This is all pretty dirty, there must be a better way to do this, can anyone help?
Take a look at the CodeIgniter download helper and the force_download function.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.