Скачивание файла через php

download.php
<?php
 
$file = urldecode($_GET['file']);
$name = urldecode($_GET['name']);
$fullPathName = __DIR__ . '/' . ltrim($file, '/');
 
if(!file_exists($fullPathName)) {
  header('HTTP/1.0 404 Not Found', true);
  die('<h1>File not found</h1>');
}
 
$ext = pathinfo($fullPathName, PATHINFO_EXTENSION);
 
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$name.'.'.$ext);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fullPathName));
 
readfile($fullPathName);
die();
.htaccess
RewriteCond %{DOCUMENT_ROOT}/download.php -f
RewriteRule ^download\.php\?.*$ download.php [L]