karthi_ms
karthi_ms

Reputation: 5698

Downloading voice file

I want to allow the user to download a voice file when he clicks the particular button on the page.I used the following code for the button action,

     window.location = "sample.mp3";

But when this statement gets executed the file gets play in the browser itself ( Im Using Firefox ).But it works for the .tar file.

Is there any way to solve this issue.

Upvotes: 0

Views: 150

Answers (3)

karthi_ms
karthi_ms

Reputation: 5698

Finally I used the following ,

Header ("Content-type: octet/stream");
Header ("Content-disposition: attachment; filename=".$file.";");
Header("Content-Length: ".Filesize($file));
Readfile($file);

Upvotes: 0

Abdullah Jibaly
Abdullah Jibaly

Reputation: 54790

Roland's answer is correct if you are downloading a dynamic binary. If it's something sitting around in your filesystem and you want Apache to set the correct headers try setting this in your .htaccess:

<Files *.mp3>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>

Upvotes: 0

Roland Mai
Roland Mai

Reputation: 31077

This has to do with the plugins enabled in your browser. They listen to particular mime types. To overcome this you need to add your own file handler. For instance, in php you can do it via disposition in the header:

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

I'm sure you can achieve a similar function with other language/frameworks.

Upvotes: 2

Related Questions