www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28

Thread: [RESOLVED] Force download of MP3 file instead of streaming

  1. #16
    Join Date
    Feb 2012
    Location
    Leesburg, Va.
    Posts
    2
    Quote Originally Posted by Eye for Video View Post
    Are you saying that the download links I posted do not work in Safari?
    The links all work just fine in Safari on my machine.
    Or are you having problems when you implement that download php file?
    My issue was that I didn't understand that the PHP code snippet is for server-side execution. I was trying to use it while hosting content on my Apple MobileMe iDisk.

    Thanks everyone for your help!

  2. #17
    Join Date
    Jan 2013
    Posts
    1

    Angry Server file proxy = HUGE SECURITY HOLE!!!!

    Please, do not create a public file proxy on your server, as suggested by "Eye for Video" and "scragar", this is a MEGA HUGE security hole , an EXTREMELY DANGEROUS feature ! Anyone could use it to download anything from the server, including password files, personal cookies, credit card information, stealing identity and even locally crack all username / passwords to remotely access your server and use it for whatever they want... NEVER CREATE A PUBLIC FILE PROXY !!! Geez...

  3. #18
    Join Date
    Apr 2006
    Posts
    66
    Just a quick thought: any zip file is downloadable. Just place your mp3 in it.

    Jack O'Connell

  4. #19
    Join Date
    Mar 2013
    Location
    Mankato, MN, USA
    Posts
    6

    Thank you!

    Thank you, all who contributed to this. You've just made things a lot easier for me. Some of my clients didn't know how to right-click a file and what to choose to save the file to their computer. Even with the instructions right there on the page, it was too difficult. Now when they click on a link, their browser asks whether they want to run or save the file. Excellent!

    I did make one modification: I put direct_download.php in a dedicated folder and link to it that way: <a href="\[my catch-all folder]\direct_download.php?file=..."> That way, I don't have to remember to copy the php file to every folder in which I'm storing files for download, and I can still use it on any page on the site.

    I need to make my site more accessible, especially to mobile users, and more standards-compliant, so I'll be studying here when I have the time.

    -- Timothy J. McGowan

  5. #20
    Join Date
    Apr 2013
    Location
    http://www.nile7.com/services
    Posts
    1
    Quote Originally Posted by MrSnowDrop View Post
    I'm using HTML/VBscript/Javascript (not PHP) in my webpages, but i thought to open a Multimedia Thread because the problem is an unwanted streaming process.

    So, how is it possible to change a MIME attribute of an MP3 file?... The need is to leave the file with his original extension because the same file is managed by a web-mediaplayer, but i'd like to let a download by clicking a specified button.
    yes , i'm wondering too

  6. #21
    Join Date
    Apr 2013
    Posts
    1

    help pls

    <?php
    //Force file download instead of streaming
    //Coded by Code018


    $file=$_GET['file'];
    $file=str_replace(" ","%20",$file);
    header('Content-type: application/octet-stream');

    // It will be called the base file name
    $url = $file;
    $file_name = basename($url);

    //lets be nice to the user and replace the spaces with happy things
    //$file_name=str_replace("%20","_",$file_name);

    //this is the filename we get to play with
    $infile = $url;
    $file_name = stristr ($infile,basename ($infile));
    header('Content-Disposition: attachment; filename="'.urldecode($song_name.mp3.'"');

    // The File source is in .mp3 originally
    //This is the file that we are downloading
    readfile(stripslashes($file));


    ?>

    when add .mp3 file download but not actual
    pls reply fast

  7. #22
    Join Date
    May 2013
    Posts
    1
    Here's how you make download link for MP3 files.
    change "octet/stream" to "audio/mp3"

  8. #23
    Join Date
    Sep 2013
    Posts
    2

    Please help

    Quote Originally Posted by Eye for Video View Post
    Another option is to use a small PHP file to handle the download, put in the same folder as the .mp3:
    Code:
    <?php
    $file = $_GET['file'];
    
    echo"$file";
    
    header ("Content-type: octet/stream");
    header ("Content-disposition: attachment; filename=".$file.";");
    header("Content-Length: ".filesize($file));
    readfile($file);
    exit;
    ?>
    which can be accessed in any anchor like this:
    Code:
    <a href="direct_download.php?file=fineline.mp3">Download the mp3</a>
    see sample page here:
    http://www.cidigitalmedia.com/tutori..._download.html
    Best of luck,
    Eye for Video
    www.cidigitalmedia.com


    when I use it in my website and browse from my iPhone then a unknown result is shown such as " Vfv7GWgw5!1AQaq"2B#R3$brCScs4%& 5DTdEU6teuFVfv'7GWgw ?:{\.8T߀]aa]vVmwX74 4HlNnoOЉۯ`?94dm[Uk h:w@99UF yC_G9-} \K*,qԗ:9iy>u _} "u2-'eU]EKlI:ۉV-.>;S> h`N+*8x*W\>j`e5.pCTnw4rnnP?]qz>Cqr{p u6Ei,p?+k*Ch $'nQ\]wjds?"*m-|'[>auɟM0qu'z2744` ]eXC\H!V{WE]v#l6zk Y춶1**Yә~Ks_}eEG{?G?2UIV+u[~uQNAeie$`_~kAiC5t;ȳ/ͫXY gnڪ5O\GGu}F? ^?῜co@/&f3VH$4.w{wSOw z+h\CegnvcSsf*sm/*XYXk]׵>^+ @*V٘?Υ4GT;0gN$ѦOʏ/ʵ"[׺Z46*r=yY*uٲ\ymU)0:GCVZzWgN{>w__qGܓQ}wC @9*L;-;&Ϻ*>]Cw*tCS%vCԩG*1s6ɘEqN^) Z)˾eL+ wI˪8,6ӑ43.........." like this.
    please help me

  9. #24
    Join Date
    Sep 2013
    Posts
    7
    All articles is amazing and very information's accounting to me.

  10. #25
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    33

    More questions

    Quote Originally Posted by bigblackpapa View Post
    Please, do not create a public file proxy on your server, as suggested by "Eye for Video" and "scragar", this is a MEGA HUGE security hole , an EXTREMELY DANGEROUS feature ! Anyone could use it to download anything from the server, including password files, personal cookies, credit card information, stealing identity and even locally crack all username / passwords to remotely access your server and use it for whatever they want... NEVER CREATE A PUBLIC FILE PROXY !!! Geez...
    Are you saying that the PHP script creates a security risk? How about changing the default Http headers?

    I am in the same boat, and tried just changing my the files metadata type to application/octet-stream but that still played the mp3. When I change it to something like application/msword it forces download and/or offers to open it in MS-Word - yikes! So I tried octet/stream, which is wrong I know but it forced download.....however I worry about people using iTunes and such, will messing with the Content-Type mess up other things?

    I'm sorry I'm not following - can someone straighten me out?

    Thanks

  11. #26
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    33
    Quote Originally Posted by CurrentWave View Post
    I worry about people using iTunes and such, will messing with the Content-Type mess up other things?
    After much testing I've found this to be true.

    Quote Originally Posted by MrSnowDrop View Post
    Hi, i had encountered problem with MP3 file links:
    in IE/Safari/Chrome, when a link to a MP3 file is clicked, the download starts correctly; but in Firefox that doesn't happen - clicking the MP3 file link, it starts an unwanted streaming through a preinstalled FF media plugin.
    I need to force MP3 file download in all browsers, is there a simple way to do that in Javascript?
    No not with Javascript, as others have said, but by using http headers and Content-Disposition one can tell all browsers that the mp3 is an attachment there by forcing the 'Save' window. Leave the Content-Type set to audio/mepg, so iTunes, etc. recognize the file.

    See these other forum posts for details -
    http://www.webdeveloper.com/forum/sh...616#post691616
    http://www.webdeveloper.com/forum/sh...200#post572200

    For older browsers make sure Content-Type appears before Content-Disposition - see this article: http://www.jtricks.com/bits/content_disposition.html

  12. #27
    Join Date
    Apr 2014
    Posts
    1
    Hi Eye for Video. Thanks for this solution which i just found on the net. I want people to download music from my site. This works on my desktop but I got someone to test it on their mobile and it just downloads the php file. Do you know is it suppose to work on mobile? Thanks a lot
    Sarah

  13. #28
    Join Date
    Apr 2014
    Posts
    1

    Unhappy

    Quote Originally Posted by Eye for Video View Post
    Another option is to use a small PHP file to handle the download, put in the same folder as the .mp3:
    Code:
    <?php
    $file = $_GET['file'];
    header ("Content-type: octet/stream");
    header ("Content-disposition: attachment; filename=".$file.";");
    header("Content-Length: ".filesize($file));
    readfile($file);
    exit;
    ?>
    which can be accessed in any anchor like this:
    Code:
    <a href="direct_download.php?file=fineline.mp3">Download the mp3</a>
    see sample page here:
    http://www.cidigitalmedia.com/tutori..._download.html
    Best of luck,
    Eye for Video
    www.cidigitalmedia.com
    Hi,

    I tried the above but when I call the .mp3 file I receive the following error message:

    Error 500: (Internal server error)

    Any thoughts?

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles