<?php

function sdir( $path='.', $mask='*', $nocache=1 ){
    static $dir = array(); // cache result in memory
    if ( !isset($dir[$path]) || $nocache) {
        $dir[$path] = scandir($path, SCANDIR_SORT_DESCENDING);
    }

    natsort($dir[$path]);

    foreach (array_reverse($dir[$path]) as $i=>$entry) {
        if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) {
            $sdir[] = $entry;
        }
    }
    return ($sdir);
} 

$dir = '/var/www/cidtool';
$files = sdir($dir, 'IdentModul*de_DE*.exe');
$newest_file = $dir . '/' . $files[0];
$basename = basename($newest_file);
$location = "/cidtool/$basename";

$size=filesize($newest_file);
header("Content-Type: application/exe");
header("Content-Disposition: attachment; filename=$basename");
header("Content-Length: $size");
header("Cache-control: private");
header("Location: $location");

?> 