我遇到問題,我生成了頁面模板的預覽並將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