Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a web-page with a linkto a sound document. When a visitor click on the link, I'd like a dialog box to pop up with possibility for the visitor to save the document on his/her local disk.
How do I accomplished this HTML coding?

How do I accomplished this HTML coding?
You don't. HTML isn't capable of this kind of interactivity. Your best bet is to use a server-side scripting language to send the sound file to the browser as an attachment, which usually triggers the open/save dialog box. There's plenty of examples of this out there...Search for content-disposition attachment php.
Of course you don't have to use php...It's just likely to be the easiest for somebody who doesn't have any programming experience.
Good luck,
-SN

OK, so I'm using php and thanks to your search suggestion, I've found the solution to my problem. For those interested, keep on reading...
Assume the mp3 file is called 'myfile.mp3' and its path is the subdirectory 'music' to your web server document directory.
On the web page with the link to the file, create the php tag:
a href='download.php?name=myfile.mp3
&path=music/myfile.mp3'Second, create the file download.php:
<?php
// get variables
$saveName = stripslashes($_GET["name"]);
$savePath = stripslashes($_GET["path"]);
// send headers to initiate a binary download
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$saveName");
header("Content-Transfer-Encoding: binary");
header("Content-length: " . filesize($savePath));
// read file
readfile($savePath);
?>When the user clicks the "download" link, a dialog box pops up.

thx 4 the code! but when I used it, the file that downloads only has 0bytes.. nothing downloads. did you have this problem??

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |