/** * Downloads a file from the folder uploads * @param string $file * @return void */ public static function DownloadFile($file) { //This condition restricts downloads only for the uploads folder if (strpos($file, "/uploads/") !== false) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $file); finfo_close($finfo); header("Content-Type: " . $mime); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: no-cache'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); } else { Logger::Error("Error downloading a file. The file url is " . $file); RequestManager::RequestError(); //Error on download, posible hacker attack... } }