<?php
// view_file.php
$exists = $pathInfo['exists'] && $pathInfo['is_file'];
$rel    = $pathInfo['rel'];
?>
<!doctype html>
<meta charset="utf-8">
<title><?= $exists ? h(basename($rel)) : '404 Not Found' ?></title>
<style>
body{font-family:system-ui;margin:24px;line-height:1.7}
code{background:#f4f4f4;padding:2px 6px;border-radius:4px}
a.btn{display:inline-block;margin-right:8px;padding:8px 12px;border:1px solid #ccc;border-radius:8px;text-decoration:none;color:#000}
a.btn:hover{background:#f7f7f7}
.muted{color:#666}
</style>
<?php if($exists): ?>
  <h1><?=h($rel)?></h1>
  <p>このファイルは画像ではありません。</p>
  <p>
    <a class="btn" href="<?= h(u_raw($rel)) ?>" target="_blank" rel="noopener">そのまま開く</a>
    <a class="btn" href="<?= h(u_down($rel)) ?>">ダウンロード</a>
  </p>
  <p class="muted">画像UIで見たい場合は対応拡張子（jpg, png, webp, gif, svg, avif 等）にしてください。</p>
<?php else: ?>
  <?php http_response_code(404); ?>
  <h1>404 Not Found</h1>
  <p>対象が見つかりませんでした。</p>
<?php endif; ?>
