7-1-1
匯出HTML及產生靜態頁面檔
您沒有觀看影片的權限
請先登入,登入後,確認您的權限後,即可觀看影片。
- 匯出功能主要是靠header來定義文件的檔頭,進而生出檔案(匯出記得關除錯)。
header("Content-type: text/html");
header("Content-Disposition: attachment; filename=檔名");
echo 主要內容;
exit;
- 利用mime-type即可將文件偽裝成各種檔案(特別是文字檔): https://www.freeformatter.com/mime-types-list.html#mime-types-list
- 建立一個
html.php
檔:
<?php
use Xmf\Request;
use XoopsModules\Tadtools\Utility;
use XoopsModules\Tad_signup\Tad_signup_actions;
require_once __DIR__ . '/header.php';
$id = Request::getInt('id');
$action = Tad_signup_actions::get($id);
header("Content-type: text/html");
// header("Content-Disposition: attachment; filename= {$action['title']}.html");
$content = "
<h2 class='my'>
{$action['title']}
</h2>
<div class='alert alert-info'>
{$action['detail']}
</div>
{$action['files']}
<h4 class='my'>
<small>
<div><i class='fa fa-calendar' aria-hidden='true'></i> 活動日期:{$action['action_date']}</div>
<div><i class='fa fa-calendar-check-o' aria-hidden='true'></i> 報名截止:{$action['end_date']}</div>
<div>
<i class='fa fa-users' aria-hidden='true'></i> 報名狀況:" . count($action['signup']) . "/{$action['number']}
<span data-toggle='tooltip' title='可候補人數'>({$action['candidate']})</span>
</div>
</small>
</h4>
<div class='text-center my-3'>
<a href='" . XOOPS_URL . "/modules/tad_signup/index.php?op=tad_signup_data_create&action_id={$action['id']}' class='btn btn-lg btn-info'><i class='fa fa-plus' aria-hidden='true'></i> 立即報名</a>
</div>
";
html5()
用法可參考:https://www.tad0616.net/modules/tad_book3/page.php?tbsn=15&tbdsn=1710
- 下載時,舊版IE可能會變成亂碼檔名,可用
iconv("UTF-8","Big5",$檔名)
,將檔名轉成Big5編碼即可。(但若遇到檔名有特殊字的,就會變成缺字了)
- 若是要把檔案存在主機上,請改用
file_put_contents ( $檔名 , $檔案內容 );
// echo $content;
if (file_put_contents(XOOPS_ROOT_PATH . "/uploads/tad_signup/{$action['id']}.html", $content)) {
header("location: " . XOOPS_URL . "/uploads/tad_signup/{$action['id']}.html");
}
exit;
- 然後編輯
templates\op_tad_signup_actions_index.tpl
加個按鈕即可
<a href="<{$xoops_url}>/modules/tad_signup/html.php?id=<{$action.id}>" class="btn btn-sm btn-primary"><i class="fa fa-html5" aria-hidden="true"></i> 匯出HTML</a>
link to https://github.com/tadlearn/tad_signup/commit/fa9806abc498f70052446706fa771c22dea1c56f \