Computing.Net > Forums > Web Development > HTML code to save document on disk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

HTML code to save document on disk

Reply to Message Icon

Name: legolas
Date: February 8, 2006 at 02:16:44 Pacific
OS: SUSE Linux 10.0
CPU/Ram: Pentium III
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: SN
Date: February 8, 2006 at 06:37:22 Pacific
Reply:

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


0

Response Number 2
Name: legolas
Date: February 9, 2006 at 07:54:32 Pacific
Reply:

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.


0

Response Number 3
Name: jocheat
Date: February 21, 2006 at 12:48:19 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: HTML code to save document on disk

Html code to open another window www.computing.net/answers/webdevel/html-code-to-open-another-window/989.html

html code for bg (sliced) image www.computing.net/answers/webdevel/html-code-for-bg-sliced-image/2811.html

Linking to Files/Documents www.computing.net/answers/webdevel/linking-to-filesdocuments/3166.html