con questo codice il download funziona però quando mi scarico il file e lo apro è corrotto, perchè?
Gli unici che non mi corrompe sono i .pdf e i .txt


Codice PHP:
<a href="../filesharing_files/utente_download_file.php?filename=<?=$rowfile5b[file]?>">
<?=strtoupper($rowfile5b['file'])?></a>


$file = $_GET['filename'];

$file = realpath($file);

    if(headers_sent()) {
        echo "Headers già inviati!";
        return false;
    } else if(!file_exists($file)) {
        echo "Il file da scaricare è inesistente!";
        return false;
    }

    $mime_types = array(
        "bmp" => "image/bmp",
        "exe" => "application/octet-stream",
        "html" => "text/html",
        "ico" => "image/x-icon",
        "jpeg" => "image/jpeg",
        "png" => "image/png",
        "jpg" => "image/jpeg",
        "mov" => "video/quicktime",
        "mp3" => "audio/mpeg",
        "mp4" => "video/mpeg",
        "mpeg" => "video/mpeg",
        "mpg" => "video/mpeg",
        "txt" => "text/plain",
        "wav" => "audio/x-wav",
        "zip" => "application/zip",
        "doc" => "application/msword",
        "m4v" => "video/x-m4v"
     );

    $bytes = filesize($file);
    $info  = pathinfo($file);
    $ext = strtolower($info["extension"]);
    $mt = isset($mime_types[$ext]) ? $mime_types[$ext] : "application/octet-stream";

    header("Content-Transfer-Encoding: binary"); 
    header("Content-Type: {$mt}");
    header("Content-disposition: attachment; filename=" . $info["filename"] . "." . $info["extension"]);
    header("Content-length: {$bytes}");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: public");

    return readfile($file);