You have issue here when you get filename using basename
$path = $_GET['filedir'] ;
$filename = $_GET['filename'];
header('Connection: Keep-Alive');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
//header('Content-Disposition: attachment;
$filename=basename($filename); //change this line;
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean();
flush();
readfile($path);
manpreet
Best Answer
2 years ago
I want to force a download of a pdf file stored on the server.
My attempts so far result in a damaged pdf file.