Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    10
    Member #
    13377
    Hi. I am trying to determine the best way to offer a music MP3 file for free download to site visitors. I design almost strictly using xhtml and css. I thought the best way to keep the user's browser from automatically playing the song instead of downloading it would be to zip the file. ANY suggestions would be greatly welcome. The idea of course is to keep the experience pain free for the site visitor. I am doing this as a promotion of a new site and it will be advertised in the next couple days! I can't figure it out! Help!

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, you could set the Mime-Type header to something like application/octet-stream. Then the browser won't know what to do with it and will require the user to save it. Do you know if the server runs Apache? If so, you can probably use a .htaccess file to make that happen.

  4. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    10
    Member #
    13377
    Quote Originally Posted by Shadowfiend
    Well, you could set the Mime-Type header to something like application/octet-stream. Then the browser won't know what to do with it and will require the user to save it. Do you know if the server runs Apache? If so, you can probably use a .htaccess file to make that happen.
    This is a bit over my head. I don't think the server runs Apache but I could certainly find out. Can you tell me a little more about the Mme-Type header, and how to set that? My programming skills are limited in this area. Thanks!

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Funny thing is, in this particular case it wouldn't really be `programming' so much as `configuring'. But in order not to waste your time, find out whether it runs Apache first, otherwise any instructions I give you will be useless and will probably just confuse you.

    As far as the concepts themselves go, part of what the server tells the browser when it sends a file, be it HTML, text, or whatever, is what type of file it is. It does this using a header that's sent before the file itself, called the Mime-Type header. If you want, you can read Wikipedia's article on MIME types for more details on what MIME is.

    The point is, the browser can decide what to do with a file depending on that MIME type. For example, if it receives a page of type text/html, the browser will generally just display it. If it receives a page of type audio/x-mp3, then it will assume it's an MP3 file and it might try and play it with an MP3 player.

    The application/octet-stream MIME type is the `generic' type that basically tells the browser `this is binary data, I don't really know of what type'. By default, most webservers send files whose type they don't know as files of type application/octet-stream. In your case, though, the server probably knows the MP3 type, so it sends it as audio/x-mp3 or something similar.

    However, most webservers also provide a way to override this default behavior and specify the type to use for certain file extensions. In Apache, you do this using a .htaccess file in the same directory as the MP3 file. I'm not sure how it's done on other webservers, however.

  6. #5
    Junior Member
    Join Date
    Jun 2006
    Posts
    10
    Member #
    13377
    Wow. That's interesting. Thanks for the information. Would you have any other quickie solutions you might recommend? The site has several .mp3 files that are intended to be listened to online. But as a promotional offer, the client wants to start offering a download of the month sort of thing. I can easily put the download of the month into a folder of it's own, in case it needs to be configured to act differently than the other mp3 files. I was thinking of offering it to be listened to first, by just linking to the sound file and letting the users player play it. And then have a download link that links to a zip file, which I think the browser would default to save, but I am not sure. I know this is all very elementary and not very sophisticated web development. But I only know so much at the moment. What you are talking about above, if I am understanding, will treat all mp3 files the same, wouldn't it? And that isn't what I want to happen.

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    It would treat all MP3 files the same in a given directory. So you can say `serve all MP3 files in the monthly/ directory as application/octet-stream'. Anythinge else will follow the server's default.

    There are plus and minus sides to a ZIP file. The plus side is it's smaller (though not by much, since MP3 is already a compressed format), and it usually gets saved instead of opened, and even if they open it, they're looking at the MP3 file, which they can then save. The minus side is, you've got to open the ZIP file to get to the MP3 file. In this particular case, I think it'd probably be best to avoid the ZIP file altogether, if possible.

  8. #7
    Junior Member
    Join Date
    Jun 2006
    Posts
    10
    Member #
    13377
    I understand. Then it sounds like I need to hear back about whether or not my servers support Apache? Then perhaps you can help me from there?
    So, is my understanding correct in that if I place all the "download" files into a monthly directory, it can then be configured to force the mp3 file to be downloaded or saved directly onto the user's hard drive? Then they can listen to it using whatever mp3 player resides on their system? And that this would be the cleanest, user friendliest way to handle this?

  9. #8
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Yes to all except the last one. I don't know if it would be the cleanest and most user-friendly way to do it. But if your goal is that you want them to download it as opposed to just listen to it, then yes, I think this is a prefectly good method. Others will agree or disagree as they will :-)

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,693
    Member #
    5580
    Liked
    717 times
    I experimented with a PHP method (see code below as example).

    It would require that the web page you are using must have the
    extension .php ... I tried it in both IE6+ and FireFox. Both browsers
    opened the dialog box with question of whether to open or save.
    There was no automatic streaming invoked.

    <?php
    $theFile = 'welcome.mp3';
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header ("Content-Type: application/octet-stream");
    header ("Content-Length: " . filesize($theFile));
    header ("Content-Disposition: attachment; filename=$theFile");
    readfile($theFile);
    ?>


    Here's the test in action:
    http://www.stlukecg.com/wimpy/force.php


    EDIT:
    doh!! I guess it didn't work ... I'll have to see why.

    EDIT AGAIN:
    The script above now works.


  11. #10
    Junior Member
    Join Date
    Jun 2006
    Posts
    10
    Member #
    13377
    This is very cool! :knockedout: I like this idea, as it gives the user a choice. Where do I place this code in my document? do I need any additional code to establish it as a php page. I don't have a lot of experience in php, but I do remember working with pages that had some sort of code at the very top of the page.
    I can just have one php page on my site though, right?


Page 1 of 3 1 2 3 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:44 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com