0

well I'm just wondering how I can get an mp3 download to start instantly, as oppose to it simply starting to play in the browser when you directly go to it.

Preferably using php headers.

So essentially when you click the file, I want a download box to appear saving save etc. Right now it just opens and starts playing in the browser.

Thanks

Belgin Fish
  • 19,187
  • 41
  • 102
  • 131
  • possible duplicate of [Forcing to download a file using PHP](http://stackoverflow.com/questions/1465573/forcing-to-download-a-file-using-php) – Ignacio Vazquez-Abrams Jun 16 '11 at 12:12
  • possible duplicate of [Php readfile - Force Download](http://stackoverflow.com/questions/3079574/php-readfile-force-download) – JohnP Jun 16 '11 at 12:13
  • behavior on open is specific to the client-side settings, but you can *suggest* an action (open/save) with `Content-Disposition` header: see e.g. this: http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment – Piskvor left the building Jun 16 '11 at 12:14
  • 1
    Possible duplicate of ABCDEFGHIJKLMNOPQRSTUVWXYZ.... – Sujit Agarwal Jun 16 '11 at 12:15

1 Answers1

2

You'll need to create a PHP file that "redirects" to the MP3 file, and point your links to that PHP file.

Code as below:

<?php
header('Content-type: audio/mpeg');
header('Content-Disposition: attachment; filename="fileName.mp3"');
readfile('originalFile.mp3');
?>

Note: The line that sets the Content-Disposition header is the critical one.

Chris
  • 4,594
  • 4
  • 29
  • 39
  • 1
    You may want to add that the second `header(...)` declaration makes the ultimate difference. (Eg. when offering an image for download.) – cimnine Jun 16 '11 at 12:26