<?php


///////// Script Code /////////


$param_URI = str_replace('/1.0/firmwares','',$_SERVER['REQUEST_URI']);

$i=1;
foreach ( explode('/',$param_URI) as $pair ) {
$param[$i] = $pair;
$i++;
}

    $yourfile = $_SERVER["DOCUMENT_ROOT"].'/downloads/'.end($param);

    $file_name = basename($yourfile);

    header("Content-Type: application/zip");
    header("Content-Disposition: attachment; filename=$file_name");
    header("Content-Length: " . filesize($yourfile));

    readfile($yourfile);


 $countFilePath = $_SERVER["DOCUMENT_ROOT"].'/downloads/count_'.$file_name.'.txt';
 $count = file_exists($countFilePath) ? file_get_contents($countFilePath) : 0;
 file_put_contents($countFilePath, ++$count);

 echo $count;

?>