<?php
session_start();

if ($_SESSION['logged_in'] === true) {
    // e.g. chelmsford/file.zip
    $file_path = $_SESSION['file_path'];

    // e.g. file.zip
    // this is used as the default filename when downloading
    $filename = pathinfo($file_path)['basename'];

    // the absolute server path to the file
    $absolute_path = '/var/www/clients/' . $file_path;

    header('Cache-Control: public');
    header('Content-Description: File Transfer');
    header("Content-Disposition: attachment; filename={$filename}");
    header('Content-Type: application/zip');
    header('Content-Transfer-Encoding: binary');

    readfile($absolute_path);
} else {
    header('Location: /');
}
?>