将PHP生成的网页下载为HTML文件 [英] Download PHP generated webpage as HTML file

查看:391
本文介绍了将PHP生成的网页下载为HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于PHP的CMS,该CMS使用< include> 添加页面的页眉和页脚,并且使用以下方法从数据库中检索页面的内容PHP / MySQL。

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.

我想在页面上创建一个按钮,以将页面下载为HTML文件-就像将页面源复制到页面时会得到的一样一个空白文件或使用浏览器保存该页面。

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.

通常,我会使用PHP来定位文件并下载,因为这是CMS生成的页面,所以这些都不是实际的文件。

Normally I would use PHP to locate the file and download it, as this is a CMS generated page these is no actual file.

有人知道如何实现吗?

(ps-目的是创建可下载的HTML电子邮件文件)

(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
?>

只需将上面的代码放在PHP文件的顶部。

Just put the above code on the top of your PHP file.

这篇关于将PHP生成的网页下载为HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆