header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); if (isset($mimes[$ext])) header("Content-Type: ".$mimes[$ext]); else header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($filename)); header('Content-Disposition: attachment; filename=' . basename($file)); set_time_limit(0); readfile($file); exit(); function mimeTypes() { $file = '/etc/mime.types'; if (!is_file($file) || !is_readable($file)) return false; $types = array(); $fp = fopen($file,"r"); while (false != ($line = fgets($fp,4096))) { if (!preg_match("/^\s*(?!#)\s*(\S+)\s+(?=\S)(.+)/",$line,$match)) continue; $tmp = preg_split("/\s/",trim($match[2])); foreach($tmp as $type) $types[strtolower($type)] = $match[1]; } fclose ($fp); return $types; }