Forum Moderators: coopster
<?php
if(isset($_POST['ok']))
{
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=new_doc.doc");
$data = "first line \n";
$data .= "second line";
echo $data;
}
?>
<form method = "post">
Download: new_doc.doc,
<input type = "submit" name = "ok" value = "OK" />
</form>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
Some text befor...
<?php
if(isset($_POST['ok']) && ($_POST['ok'] == "OK"))
{
header('Content-type: application/msword');
header("Content-Disposition: attachment; filename=New_doc.doc");
$data = "first line \n";
$data .= "second line";
echo $data;
exit;
}
?>
<form action="" method = "post">
Download: new_doc.doc,
<input type = "image" src = "button.jpg" name = "ok" value = "OK" />
</form>
Some text after...
</body>
</html>
<?php
if(isset($_POST['ok']) && ($_POST['ok'] == "OK"))
{
header('Content-type: application/msword');
header('Content-Disposition: attachment; filename="New_doc.doc"');
$docText = "first line \n\r";
$docText .= "second line\n\r";
$docText .= "More text\n\r";
$docText .= "Even more text\n\r";
$docText .= "This is now working people!\n\r";
echo $docText;
exit;//The exit will stop the script echoing anything else :)
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
Top form text
<form action="" method="post">
Download the new .doc file
<input type="submit" name="ok" value="OK" />
</form>
Thanks
</body>
</html>