HTML code to save document on disk

February 8, 2006 at 02:16:44
Specs: SUSE Linux 10.0, Pentium III
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?

See More: HTML code to save document on disk

Report •

February 8, 2006 at 06:37:22
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,

Report •

February 9, 2006 at 07:54:32
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

Second, create the file download.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



When the user clicks the "download" link, a dialog box pops up.

Report •

February 21, 2006 at 12:48:19
thx 4 the code! but when I used it, the file that downloads only has 0bytes.. nothing downloads. did you have this problem??

Report •

Related Solutions

Ask Question