ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Forcing Download

December 18, 2008 5:36pm

Subscribe [4]
  • #1 / Dec 18, 2008 5:36pm

    [email protected]

    119 posts

    I am looking for a way that I can force people to download an MP3 off of a link rather than streaming it through a browser plugin. Right now I have the link set up as a direct link but when you click on it the browser opens the file instead of downloading it. Any thoughts on how I can force this to happen, let me know, thanks!

  • #2 / Dec 18, 2008 6:13pm

    Derek Jones

    7561 posts

    Have a look at the Download Helper in CodeIgniter.  It wouldn’t be a straight cut and paste, as it has a dependancy on the CI mime type file, but the basic process is the same: read the file with PHP, and then send it with an attachment Content-Disposition with binary encoding.

  • #3 / Dec 18, 2008 6:38pm

    Mark Bowen

    12637 posts

    Alternatively you could take a look at the LinkLocker module that Brad made a while ago. A really neat addition to ExpressionEngine if you don’t want to code something yourself.

  • #4 / Dec 19, 2008 10:21am

    [email protected]

    119 posts

    The LinkLocker Module seems to be what I need but it seems to be masking too well. Once the file downloads it gives me a very long file name and doesn’t know what type of file it is. I am trying to do this with mp3’s off of a libsyn podcast broadcast. Take a look here: http://www.lcbcchurch.com/splash2 and navigate to the listen tab. Then try and click on the PC link for the podcast named “Just Ask - Guest Speaker”. Any help you can provide would be greatly appreciate, thanks!

  • #5 / Dec 19, 2008 10:43am

    [email protected]

    119 posts

    Please disregard my last message…I was too trigger happy on the post. LinLocker is working great, thanks!

  • #6 / Dec 19, 2008 10:46am

    Mark Bowen

    12637 posts

    Please disregard my last message…I was too trigger happy on the post. LinLocker is working great, thanks!

    Excellent news. It really is a great addition that one.

  • #7 / Dec 23, 2008 7:51am

    Jedidiah

    24 posts

    Sounds like you have it sorted now, but If you just want the file to download and aren’t bothered about people knowing the url of the file the simplest way would be to add something like this to your htaccess file

    AddType application/octet-stream .mp3

    That would force files ending in .mp3 that are linked to, to download; if they are embedded they will still play.


    edit: fixed typo

  • #8 / Jan 16, 2009 12:58pm

    fanderson

    899 posts

    Would this htaccess code work for .aif and .wav files as well?

  • #9 / Jan 16, 2009 1:04pm

    Jedidiah

    24 posts

    Yes would work fine. I think you can just add them onto the end, so it would be

    AddType application/octet-stream .mp3 .aif .wav .pdf

    If that doesn’t work just put each one on a new line

    AddType application/octet-stream .mp3
    AddType application/octet-stream .aif
    AddType application/octet-stream .wav
    AddType application/octet-stream .pdf
  • #10 / Jan 16, 2009 1:11pm

    fanderson

    899 posts

    Works perfectly. Thank you.

  • #11 / Feb 12, 2009 1:45pm

    Joey Marchy

    22 posts

    I was able to force downloads with .htaccess rules. I placed these rules in my .htaccess file in the root:

    <Files *.png>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
    </ Files>
  • #12 / Mar 17, 2010 2:32pm

    [email protected]

    119 posts

    Sounds like you have it sorted now, but If you just want the file to download and aren’t bothered about people knowing the url of the file the simplest way would be to add something like this to your htaccess file

    Is there any particular place that I need to put them within the .htaccess file…for some reason it isn’t working.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases