save button ?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Guy
Forum Commoner
Posts: 53
Joined: Sun Jan 12, 2003 3:34 am

save button ?

Post by Guy »

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?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

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).

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);
	}
?>
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.
Post Reply