ページに .html ファイルを直接書き込んで作成し、それをユーザーが自分のローカル マシンにダウンロードできるようにする必要があります。.html ファイルは、データベース要求からの完全な OS 情報になります。次のようになります。
<?php
$content = "<!DOCTYPE html><html lang="en"><head></head><body>";
$content .= "<div>Hello World</div>";
$content .= get_all_contents_from_db();
$content .= "</body></html>";
?>
次のコードを使用して、表示しているページをファイルにダウンロードできるコードを見ました。
<?php
if(isset($_POST['download']))
{
header("Content-Disposition: attachment; filename=\"" . basename($File) . "\"");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($File));
header("Connection: close");
}
?>
So the question is: How do I create a downloadable html file using php?
**PART 2**
<form method="POST" action=''>
<button name="download">Download File</button>
</form>
<?php
$content = "<!DOCTYPE html><html lang=\"en\"><head></head><body>";
$content .= "<div>Hello World</div>";
$content .= "</body></html>";
if(isset($_POST['download'])){
echo $content;
header("Content-Disposition: attachment; filename=\"slideshow.html\"");
header("Content-Length: " . filesize($content));
echo $content;
}
?>
出力
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<div class="main">Dashboard</br>
<form method="POST" action=''>
<button name="download">Download File</button>
</form>
<!DOCTYPE html><html lang="en"><head></head><body><div>Hello World</div></body></html><!DOCTYPE html><html lang="en"><head></head><body><div>Hello World</div></body></html> </div>
</div>
</body>
</html>