0

好的,所以我有一个表格。我希望能够输入信息,当我点击提交按钮时,以格式化的方式下载信息。

例如,这是一个基本形式

<html>
<body>
        <form action="submit.php" method="post">
                    <table>
                        <tr>
                <td>Week of:</td>
                <td><input type="text" name="week"></td>
            </tr>
            <tr>
                            <td>Monday:</td>
                <td><input type="text" name="mon"></td>
            </tr>
            <tr>
                <td>Tuesday:</td>
                <td><input type="text" name="tue"></td>
            </tr>
            <tr>
                <td>Wednesday:</td>
                <td><input type="text" name="wed"></td>
            </tr>
            <tr>
                <td>Thursday:</td>
                <td><input type="text" name="thur"></td>
            </tr>
            <tr>
                <td>Friday:</td>
                <td><input type="text" name="fri"></td>
            </tr>

            <input type="submit">
        </form>
    </table>

</body>
</html>

这里是提交页面。

<html>
<body>
Your schedule for the week of <?php echo $_POST["week"]; ?> !<br>
Monday <?php echo $_POST["mon"]; ?> <br>
Tuesday <?php echo $_POST["tue"]; ?> <br>
Wednesday <?php echo $_POST["wed"]; ?> <br>
Thursday <?php echo $_POST["thur"]; ?> <br>
Friday <?php echo $_POST["fri"]; ?> <br>
</body>
</html>

提交页面以不同的格式显示信息。如何将信息下载到像这样的文本文档中?

4

1 回答 1

1

查看: http: //php.net/manual/en/function.header.php

您需要以您喜欢的格式格式化您的数据,之后您可以执行类似的操作:

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>
于 2013-05-12T06:11:23.597 回答