5

ページのヘッダーとフッターを追加するために使用する PHP ベースの CMS を使用<include>しています。ページのコンテンツは、PHP/MySQL を使用してデータベースから取得されます。

ページのソースを空のファイルにコピーしたり、ブラウザでページを保存した場合と同じように、ページを HTML ファイルとしてダウンロードするボタンをページに作成したいと考えています。

これは CMS で生成されたページであり、実際のファイルではないため、通常は PHP を使用してファイルを見つけてダウンロードします。

これを達成する方法を知っている人はいますか?

(ps - これの目的は、ダウンロード可能な HTML メール ファイルを作成することです)

4

2 に答える 2

7
<?php
$filename = 'filename.html';
header('Content-disposition: attachment; filename=' . $filename);
header('Content-type: text/html');
// ... the rest of your file
?>

上記のコードを PHP ファイルの先頭に置くだけです。

于 2012-10-26T05:12:56.160 に答える
5

これは file_get_contents(); で試すことができます。

<?php

 //Link to download file...
 $url = "http://example.com/test.php";

 //Code to get the file...
 $data = file_get_contents($url);

 //save as?
 $filename = "test.html";

 //save the file...
 $fh = fopen($filename,"w");
 fwrite($fh,$data);
 fclose($fh);

 //display link to the file you just saved...
 echo "<a href='".$filename."'>Click Here</a> to download the file...";

?>
于 2012-10-26T05:18:30.467 に答える