<?php $db = new mysqli('localhost', 'root', '12345', 'test'); $db->set_charset("utf8"); $sn = $db->real_escape_string($_GET['sn']); $sql = "SELECT `type`,`content` FROM `canvas` where `sn`='{$sn}'"; $result = $db->query($sql) or die($db->error); list($type, $content) = $result->fetch_row(); echo "<img src='data:" . $type . "," . $content . "'>"; $sql = "SELECT * FROM `canvas` order by `sn` desc"; $result = $db->query($sql) or die($db->error); while (list($sn, $type, $content) = $result->fetch_row()) { if (strpos($type, 'svg') !== false) { $pic = "{$sn}.svg"; } else { $pic = "{$sn}.png"; } echo " <div> <a href='show.php?sn=$sn'> <img src='$pic' style='width: 200px; border:1px solid gray; margin: 4px;'> </a> </div>"; } echo '<a href="index.html">回首頁</a>';