I have a problem with php force download. I tried a lot of code but no one resolve problem. I need to download file with php (the name of file is sent with querystring and files are stored in a folder protected by htaccess). With this code I can download for example a pics (the browser correctly ask with file dialog where saving it) but when I try to download a pdf file the browser don't open file dialog and save it in default download folder and automatically open pdf with default pdf viewer. Is there a possibility to open file dialog for pdf file and download like other file like pics without automatic download and opening it?
$file = $_GET['file'];
$url = "{$_SERVER['DOCUMENT_ROOT']}images/files/".$file;
header("Pragma: public");
header("Expires: 0");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header('Content-disposition: attachment; filename=' . basename($url));
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($url));
@readfile($url);
exit(0);