将 PHP 生成的网页下载为 HTML 文件
我正在使用基于 PHP 的 CMS,它使用 <include>
添加页面的页眉和页脚,并使用 PHP/MySQL 从数据库中检索页面内容.p>
我想在页面上创建一个按钮,将页面下载为 HTML 文件 - 就像您将页面源复制到空白文件或使用浏览器保存页面一样.
通常我会使用 PHP 来定位文件并下载它,因为这是一个 CMS 生成的页面,这些不是实际文件.
有谁知道如何做到这一点?
(ps - 这样做的目的是创建一个可下载的 HTML 电子邮件文件)
解决方案
只需将上述代码放在 PHP 文件的顶部即可.
I am using a PHP based CMS which uses <include>
to add the header and footer of the page, and the content of page is retrieved from a database using PHP/MySQL.
I want to create a button on the page that downloads the page as a HTML file - just like what you would get if you copied the page source onto a blank file or saved the page with your browser.
Normally I would use PHP to locate the file and download it, as this is a CMS generated page these is no actual file.
Does anyone know how to achieve this?
(ps - the aim of this is to create a downloadable HTML email file)
解决方案<?php
$filename = 'filename.html';
header('Content-disposition: attachment; filename=' . $filename);
header('Content-type: text/html');
// ... the rest of your file
?>
Just put the above code on the top of your PHP file.
相关文章