init: projet complet copymail pour Raspberry Pi
Stack: Nginx + PHP 8.2 + MariaDB + Postfix + Dovecot + Samba - install.sh: script installation automatisé pour RPi OS Bookworm - Interface web: visionneuse mails + admin (comptes, domaine, dashboard) - Chaque compte mail génère automatiquement un share Samba - Processeur cron: extraction pièces jointes via zbateson/mail-mime-parser - Zéro injection SQL (PDO + prepared statements) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
33
web/mail/download.php
Normal file
33
web/mail/download.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/db.php';
|
||||
require_once __DIR__ . '/../includes/auth.php';
|
||||
|
||||
auth_check();
|
||||
|
||||
$id = (int)($_GET['id'] ?? 0);
|
||||
if (!$id) { http_response_code(400); exit('bad request'); }
|
||||
|
||||
$st = db()->prepare('SELECT file_name, path FROM files WHERE id = ?');
|
||||
$st->execute([$id]);
|
||||
$row = $st->fetch();
|
||||
|
||||
if (!$row || !file_exists($row['path'])) {
|
||||
http_response_code(404);
|
||||
exit('Fichier introuvable.');
|
||||
}
|
||||
|
||||
$ext = strtolower(pathinfo($row['file_name'], PATHINFO_EXTENSION));
|
||||
$mime = match($ext) {
|
||||
'pdf' => 'application/pdf',
|
||||
'jpg', 'jpeg' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'csv' => 'text/csv',
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
default => 'application/octet-stream',
|
||||
};
|
||||
|
||||
header('Content-Type: ' . $mime);
|
||||
header('Content-Disposition: attachment; filename="' . addslashes($row['file_name']) . '"');
|
||||
header('Content-Length: ' . filesize($row['path']));
|
||||
readfile($row['path']);
|
||||
Reference in New Issue
Block a user