-1

Possible Duplicate:
How to force download of a file?

How to download a file that directly opens in the browser by default. For ex- In older browsers, if I opened a link of a mp3 song, then it were downloaded; but now-a-days, they start playing in the browser itself. One method is to right-click the link and click save link as and then save the song; but many times, the link provided is a mask to some other link which is actually the song. So what to do in this case?

Community
  • 1
  • 1
kushpf
  • 1,078
  • 10
  • 22
  • Do you have access to the webserver configuration files? – nkr Aug 14 '12 at 11:39
  • @nkr - I don't know. I have to download something from some random website. I don't know how to access webserver configuration file. I don't know even what is webserver configuration file. Sorry. – kushpf Aug 14 '12 at 11:43
  • So your question is not about programming? – nkr Aug 14 '12 at 11:46
  • @nkr - It's about programming only. I want to program some method to download the file instead of running it on the browser. – kushpf Aug 15 '12 at 03:57

1 Answers1

1

You need to set the content disposition to attachment in the header like this:

header('Content-Disposition: attachment');

Also to Include a file name you can use :

header('Content-Disposition: attachment; filename=abc.mp3');

Or maybe configure apache[if you're on apache] to have this defined for filetypes you want to force download, like

<FilesMatch "\.(mp3|mov|pdf)">
    Header set Content-Disposition attachment
</FilesMatch>
Amyth
  • 32,527
  • 26
  • 93
  • 135