表示するphpファイル
写真が2枚の時は、vertical-align:topで上揃えにします。
<style>
#menu {
border: solid 1px #f0f8ff;
font-size:small;
color:#d3d3d3;
padding-left:10px;
}
#img{
position: relative;
}
#img img{
vertical-align:top;
}
</style>
<?php
$id = 15;
$dsn = "mysql:dbname=mail;host=localhost";
$user = "hoge";
$password = "hogehoge";
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e){
print('connection failed:'.$e->getMessage());
}
$sql = "select * from sends where id = '".$id."'";
$stmt = $dbh->query($sql);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$send_from = $result['username'];
$send_sub = $result['subject'];
$send_body = $result['body'];
$sendtime = $result['sendtime'];
$file1 = $result['file1'];
$file2 = $result['file2'];
echo "<h3>".$send_sub."</h3>";
echo "From: ".$send_from. "<br>";
echo $sendtime. "<hr>";
echo $send_body. "<br>";
if(!empty($file2)){
echo "<br><div id=\"img\"><img src=\"".$file1."\"> <img src=\"".$file2."\"></div><br>";
echo "<a href=\"wa.php?id=".$file1."\">1.ダウンロード</a> <a href=\"wa.php?id=".$file2."\">2.ダウンロード</a><br>";
}elseif(!empty($file1)){
echo "<br><img src=\"".$file1."\"><br>";
echo "<a href=\"wa.php?id=".$file1."\">ダウンロード</a><br>";
}
?>
<br>
<div id="menu"> <a href="?compose=reply&inbox=<?php echo $id; ?>">返信する</a> | <a href="?path=todelete&inbox=<?php echo $id; ?>">削除</a> | <a href="?path=tojunk&inbox=<?php echo $id; ?>">ジャンク</a></div>
ダウンロード押下すると、wa.phpで生成した画像ファイルをダウンロードします。
拡張子に応じて、switch文で切り替えます。
wa.php (web access ※outlookの真似をしました)
<?php
$fpath = $_GET['id'];
$ext = substr($fpath, strrpos($fpath, '.') + 1);
$date = date(Ymdhis);
switch ($ext) {
case 'jpeg':
$fname = "".$date.".jpeg";
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($fpath));
header('Content-disposition: attachment; filename="'.$fname.'"');
readfile($fpath);
break;
case 'gif':
$fname = "".$date.".gif";
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($fpath));
header('Content-disposition: attachment; filename="'.$fname.'"');
readfile($fpath);
break;
case 'png':
$fname = "".$date.".png";
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($fpath));
header('Content-disposition: attachment; filename="'.$fname.'"');
readfile($fpath);
break;
default:
$fname = "".$date.".jpg";
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($fpath));
header('Content-disposition: attachment; filename="'.$fname.'"');
readfile($fpath);
break;
}
?>
まーいいんじゃないでしょうか。

添付が1枚の時

つなげると、

OK! Good!
さて、idはauto incrementではなく、乱英数字8桁くらいにしたいですね。
$str = array_merge(range('a','z'), range('0', '9'), range('A', 'Z'));
$r_str = null;
for($i = 0; $i < 8; $i++){
$r_str .= $str[rand(0, count($str) - 1)];
}
echo $r_str;
ほい





























