<?php

    $file = $_GET['ffilepath'];

    $ext = pathinfo($file, PATHINFO_EXTENSION);
    $basename = pathinfo($file, PATHINFO_BASENAME);

    // Process download
    if(file_exists($file)) {
        header("Expires: 0");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
        header("Content-type: application/".$ext);
        header('Content-Length: ' . filesize($file));
        header("Content-Disposition: attachment; filename=\"$basename\"");
        ob_clean();
        flush();
        readfile($file);
        die();
    } else {
        http_response_code(404);
      die();
    }
?>
