We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom headers

Development and Programming

Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

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?

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

Take a look at the CodeIgniter download helper and the force_download function.

       
Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

That doesn’t work, the output class already sends some headers out.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.