Simple file downloader
<p>I am fairly new to php and have managed to string together this simple download script by reading some of the questions listed here at SO and would like to ask those of you that are more familiar with php to take a look at the code below and see if there are any glaring flaws with my implementation or anything that should be changed.</p>

<p>Just letting you know that the during my limited testing, everything seemed to work fine, but as I said I am fairly new to php and want to make sure I am not missing something that might break the script later down the road. </p>

<pre><code>&lt;?php

//Settings
$filesPath   = './files';
$fileName    = $_GET['file'];
$allowedExts = array('jpg','png','gif');


//Functions 
//Returns the extension portion of a filename.
function file_extension($fileName)
{
    $path_info = pathinfo($fileName);
    return strtolower($path_info['extension']);
}

//Validation and processing
//Check that a file is actually being requested
if (empty($fileName)) {
    die('no file was requested');
}

//Check that the file is allowed to be downloaded   
if (!in_array(file_extension($fileName), $allowedExts)) {
    die('you cannot download this file');
}

//Get the file  
if (file_exists($filesPath . DIRECTORY_SEPARATOR . $fileName)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . basename($fileName));
    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($fileName));
    ob_clean();
    flush();
    readfile($fileName);
    exit;
}
?&gt;
</code></pre>

<p>TIA,
Dave</p>
