Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts

    .mp3 download link/image

    Hey guys,

    i have an image that links to a .mp3 file that people can download, but instead of going to the download box, it opens up quicktime and starts playing it. is there a code to make it not play with quicktime? this is firefox btw, haven't tried ie.

  • #2
    New Coder
    Join Date
    Jan 2009
    Posts
    84
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I'm not expert here... but this has to do with MIME types. The approach I see taken most often is the one that says "right click this link, and select 'save as' to download". The reason is because the browser typically understands the association of the file being linked and some application on your computer. It IS ( I believe ) possible to force a different kind of download stream... not my area of expertise.

  • #3
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    It's done by a HTTP header. If you want to suggest a filename for the user, add the bit in red.
    Code:
    
    Content-Disposition: attachment; filename=song.mp3
    
    Add this by PHP or a .htaccess file.

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CyanLight View Post
    It's done by a HTTP header. If you want to suggest a filename for the user, add the bit in red.
    Code:
    
    Content-Disposition: attachment; filename=song.mp3
    
    Add this by PHP or a .htaccess file.
    so I add that whole thing into the .htaccess file: Content-Disposition: attachment; filename=song.mp3

    Or do I have to add each file name. There's about 50 different .mp3's.

    Heres the site:

    www.baysidesuperior.org/Bayside/media

  • #5
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Assuming you're on an Apache webserver, open the .htaccess file. Inside it, copy & paste:
    Code:
    
    <FilesMatch "\.mp3$">
    <IfModule mod_headers.c>
    Header set Content-Disposition "attachment"
    </IfModule>
    </FilesMatch>
    
    Hopefully, that should work.

  • #6
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Awesome thanks!

  • #7
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CyanLight View Post
    Assuming you're on an Apache webserver, open the .htaccess file. Inside it, copy & paste:
    Code:
    
    <FilesMatch "\.mp3$">
    <IfModule mod_headers.c>
    Header set Content-Disposition "attachment"
    </IfModule>
    </FilesMatch>
    
    Hopefully, that should work.
    Ok I thought that worked but I tried it on a few other computers using firefox and ie and they both just starting streaming it. Any thoughts?

  • #8
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I looked a few places and I found one site doing this:

    http://SITE.org/download.php?file=01_cca09-06-211.mp3

    So correct me if I'm wrong..the links the image to the file "download.php" then in the .php there is code that links 01_cca09-06-211.mp3 to the real name of the .mp3?

    If that's right, what would the php code be?

  • #9
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Okay, create a file named download.php. Inside it, paste:
    PHP Code:
    <?php
      $file 
    $_GET['file'];
      if(
    file_exists($file ".mp3")) {
        
    header("Content-Type: audio/mpeg");
        
    header("Content-Disposition: attachment; filename=$file.mp3");
        include(
    $file ".mp3");
      }
      else {
        
    header("Content-Type: text/html; charset=utf-8");
    ?>
    <!doctype html>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Error: File doesn&rsquo;t exist!</title>
        <style type="text/css">
    html {
      font: .8125em/1.8 'lucida grande', 'lucida sans unicode', sans-serif;
    }
    body {
      padding: .75em 1.5em;
      margin: 0;
      background: #fff;
      color: #222;
    }
    p {
      margin: .75em 0;
    }
    a {
      color: #39f;
      text-decoration: none;
    }
    a:hover {
      color: #06c;
    }
        </style>
      </head>
      <body>
        <p><strong>An error has occured</strong>. This file doesn&rsquo;t exist on this server. If you followed a legitimate link, please help us out and <a href="/contact">contact us</a>, so we can both fix this and redirect you to the file you wanted. Thank you.</p>
        <p>&laquo; <a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Go back</a></p>
      </body>
    </html>
    <?php
      
    }
    ?>
    Now, link to your files as http://example.com/download.php?file=filename, replacing example.com and filename as appropriate (do not put .mp3 on the end.) This should do you.

  • #10
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok I put the download.php in the folder with all my mp3's, then linked to http://baysidesuperior.org/Sermons/d...?file=FILENAME but it downloads this really weird file that says this when I open it with notpad:

    <br />
    <b>Warning</b>: Unexpected character in input: '' (ASCII=30) state=1 in <b>/home4/baysides/public_html/Sermons/06.21.09 - One Body, Many Parts.mp3</b> on line <b>294</b><br />
    <br />
    <b>Parse error</b>: syntax error, unexpected T_STRING in <b>/home4/baysides/public_html/Sermons/06.21.09 - One Body, Many Parts.mp3</b> on line <b>294</b><br />
    Last edited by rickfink; 06-27-2009 at 05:50 PM.

  • #11
    New Coder
    Join Date
    Jan 2009
    Posts
    83
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Any suggestions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •