我有一個文件,index2.php已被寫入一個表單。在PHP中彈出另存爲對話框
這個文件的全部內容,我已經存儲在一個變量$final_code
使用輸出緩衝區。
我現在希望在頁面末尾添加一個「下載」按鈕,這會彈出另存爲對話框,允許用戶將該文件的源代碼(即變量)保存爲.txt - 但是我「難倒了。
index2.php:
<?php
// Start buffering the output
ob_start();
?>
<!-- INDEX2.PHP HTML ELEMENTS HERE -->
<?php
// Store the contents of the buffer
$final_code = ob_get_contents();
// Print the contents of the buffer
ob_end_flush();
?>
<form action="savefile.php" method="post">
Happy? Save this to file: <input type="submit" name="savefile" value="Save" />
</form>
我不知道這是否需要這個文件或savefile.php進行工作,所以後者目前是空白。
看到[這個SO問題](http://stackoverflow.com/questions/4458119/display-save-as-dialog-and-save-contents-of-a-selected-text-inside-textarea-to) – jaudette