我遇到问题,我生成了页面模板的预览并将HTML保存到template.php
文件。只要文件template.php
包含它应该包含的内容,那么当你点击按钮时,生成的文件是空的 - 为什么?尽管包含内容,函数返回空文件
我有两个文件 - generate.php(含预览的生成,并在未来形成一个按钮,生成下载)
Get.php - 脚本下载文件
GENERATE .PHP
<?php
$template = ob_get_flush();
$fp = fopen('template.html', 'w');
fwrite($fp, $template);
fclose($fp);
file_put_contents('template.html', $template);
?>
<form method="post" action="get.php">
<div id="container">
<input type="submit" id="download" value="Download template"/>
</div>
</form>
GET.PHP
<?php
$download = file_get_contents('./template.html');
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=template.html');
header('Content-length: '.strlen($download));
?>
为什么在'generate.php'你要写两次文件? – RiggsFolly
你在文件上写什么数据 – Bhargav
这行代码是用于其他PHP版本 – Montana