File: /var/www/net/download.php
<?php
$base = "/ftp";
if (!isset($_GET['id'])) {
exit("Missing identity");
}
$id = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['id']);
$file = "$base/$id.backup";
if (!file_exists($file)) {
echo "
<script>
alert('找不到 {$id} 備份檔,請洽網管部。');
history.back();
</script>
";
exit;
}
// 取得檔案最後修改時間(FTP upload time = mtime)
$mtime = filemtime($file);
$date = date("Y-m-d", $mtime);
// 新檔名(只含日期)
$downloadName = $id . "_" . $date . ".backup";
// header下載
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$downloadName\"");
header("Content-Length: " . filesize($file));
readfile($file);
exit;