I want to enable people to save my page with a click of a button.
how can I open a save dialog for my page from a button ?
like when you press ctrl-s from the browser?
save button ?
Moderator: General Moderators
That's actually more a server-side question.
You will need the page sitting on your server as a file, not pulled, even in bits, from your database.
If someone clicks the button "save this page", submit a form to PHP-script which sends your webpage via HTTP (see below).
IE 5.5 has a bug in how it treats downloads, that's why octet-stream is specified as MIME-type. The script above works with all browsers I know of.
Do a search on zend.com and php.net for "header" which will clarify many things.
You will need the page sitting on your server as a file, not pulled, even in bits, from your database.
If someone clicks the button "save this page", submit a form to PHP-script which sends your webpage via HTTP (see below).
Code: Select all
<?php
if ($_POST["download"])
{
header("Cache-control: private");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=yourwebpage.html");
header("Content-length: ".filesize($filename)."\\n");
//send file contents
$fp=fopen($filename, "r");
fpassthru($fp);
}
?>Do a search on zend.com and php.net for "header" which will clarify many things.