MHT (MIME HTML) 是微軟專有封裝格式,僅 IE 原生支援。其他瀏覽器無法直接渲染,會觸發下載。
客戶端 iframe → 伺服器端解析 MHT → 轉換為標準 HTML → 回傳瀏覽器渲染
<?php
// view_mht.php
$mhtPath = $_GET['file'];
$content = file_get_contents($mhtPath);
// 解析 MHT 邊界分隔符
$boundary = parseBoundary($content);
$parts = splitParts($content, $boundary);
foreach ($parts as $part) {
if (isHtmlPart($part)) {
echo extractHtmlBody($part);
break;
}
}
function parseBoundary($content) { ... }
?>
<iframe src="view_mht.php?file=doc.mht" width="100%" height="600"></iframe>
核心思路:將專有格式在伺服器端標準化,客戶端無感知。