【发布时间】:2017-08-12 18:28:58
【问题描述】:
我想用 PHP 制作一个简单的 HTML 文件生成器,用户在其中输入一些数据,然后 .php 文件生成带有 HTML 代码的输出,包括来自用户的数据。
问题是我的生成器只生成了一个空白的 .html 文件。
表格很简单:
<form action="html_form_submit.php" method="post">
<textarea name="name" rows="2" cols="20"> </textarea>
<input type="submit" value="Submit"/></form>
还有html_form_submit.php 文件:
<?php
ob_start();
$name = @$_POST['name'];
?>
<html><body>
Name: <?php echo $name; ?><br>
</body></html>
<?php
$output = ob_get_contents();
$filename = 'test.html';
!$handle = fopen($filename, 'w');
fwrite($handle, $output);
fclose($handle);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize("$filename").";");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
readfile($filename);
ob_end_clean();
?>
你知道问题出在哪里吗?
【问题讨论】: