File "test_send_modal_01.php"

Full Path: /home/analogde/www/Administratif/FTP/Monsta-FTP-master/test_send_modal_01.php
File size: 4.62 KB
MIME-type: text/x-php
Charset: utf-8

<?php
// Détecter si un fichier doit être téléchargé

// $chemin = "/home/analogde/www/Document_workarea/patrice/Test";
//$fichier = "picamera.pdf";


if (isset($_GET['download'])) {
    $fileId = intval($_GET['download']);
    $files = [
        1 => '/home/analogde/www/Document_workarea/patrice/Test/capture_IC616.jpg',
        2 => '/home/analogde/www/Document_workarea/patrice/Test/capture_IC616_v01.jpg',
        3 => '/home/analogde/www/Document_workarea/patrice/Test/capture_IC616_v02.jpg',
        4 => '/home/analogde/www/Document_workarea/patrice/Test/capture_IC616_v03.jpg',
    ];

    if (isset($files[$fileId]) && file_exists($files[$fileId])) {
        $filePath = $files[$fileId];
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($filePath));
        ob_clean();
        flush();
        readfile($filePath);
        exit();
    } else {
        echo '<div class="alert alert-danger text-center">Fichier introuvable.</div>';
    }
}

// Données pour remplir les colonnes
$rows = [
    ['nom' => 'Fichier 1', 'taille' => '10 Mo', 'heure' => '12:30'],
    ['nom' => 'Fichier 2', 'taille' => '20 Mo', 'heure' => '13:00'],
    ['nom' => 'Fichier 3', 'taille' => '15 Mo', 'heure' => '14:15'],
    ['nom' => 'Fichier 4', 'taille' => '50 Mo', 'heure' => '15:45'],
];
?>

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Téléchargement avec boîte de dialogue</title>
    <!-- Lien vers Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script>
        // Fonction pour afficher la modale avec l'ID du fichier
        function showModal(fileId) {
            const validateButton = document.getElementById('validateDownload');
            validateButton.href = "?download=" + fileId;
            const modal = new bootstrap.Modal(document.getElementById('actionModal'));
            modal.show();
        }
    </script>
</head>
<body>
    <div class="container mt-5">
        <h1 class="text-center mb-4">Téléchargement avec boîte de dialogue</h1>

        <!-- Tableau -->
        <table class="table table-striped table-hover table-bordered">
            <thead class="table-dark">
                <tr>
                    <th>Nom</th>
                    <th>Taille</th>
                    <th>Heure</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $index => $row): ?>
                    <tr>
                        <td><?= htmlspecialchars($row['nom']) ?></td>
                        <td><?= htmlspecialchars($row['taille']) ?></td>
                        <td><?= htmlspecialchars($row['heure']) ?></td>
                        <td>
                            <!-- Bouton pour ouvrir la modale -->
                            <button onclick="showModal(<?= $index + 1 ?>)" class="btn btn-primary btn-sm">
                                Télécharger
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>

    <!-- Fenêtre modale Bootstrap -->
    <div class="modal fade" id="actionModal" tabindex="-1" aria-labelledby="actionModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="actionModalLabel">Confirmer le téléchargement</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    Voulez-vous télécharger ce fichier ?
                </div>
                <div class="modal-footer">
                    <a id="validateDownload" href="#" class="btn btn-success">Valider</a>
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Lien vers Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>