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

查看:40
本文介绍了将 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.

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

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