ダウンロードリンク:
<a href="download.php?words=2000&sort=popular&type=xml">Download php file</a>
download.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Home</title>
</head>
<body>
<h1>PHP file</h1>
<?php
function get_text($text)
{
....
}
function get_time($time)
{
....
}
$url = "http://api.xxx.com/info.php?words=".$_GET['words']."&sort=".$_GET['sort']."&type="$_GET['type'];
$xml = simplexml_load_file($url);
if (count($xml))
{
foreach($xml->book as $book)
{
echo ....
}
}
?>
</body>
</html>
download.phpは、ウェブマスターがFTPにアップロードできるようにするための既製のAPIphpスクリプトです。ウェブマスターは、フォームから多くのオプション(例:download.php?words = 2000&sort = Popular&type = xml)を選択し、フォームを送信してカスタムAPIスクリプトを取得できます。
これは、フォームを送信した後にオプションを置き換える行です。
$url = "http://api.xxx.com/info.php?words=".$_GET['words']."&sort=".$_GET['sort']."&type="$_GET['type'];
これは、ダウンロードを強制するためのコードです。しかし、ページ全体を$ content="";で折り返す方法がわかりません。HTMLコードをラップする方法は知っていますが、ページ上のPHP関数とコードをラップする方法はありますか?
header("Content-Disposition: attachment; filename="download.php");
print $content;