Perhaps you are running into a memory/filesize error? I've had problems in the past dumping large files with readfile. In addition to setting the Content-Length header, I recommend using fpassthru()
, as it does not read the file into a buffer, it just dumps it.
set_time_limit(0); // disable timeout
$file = $root_path.'/full-tile-book.pdf';
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="NewName.pdf"');
header('Content-Length: ' . filesize($file));
session_write_close(); // remove this line if sessions are not active
$f = fopen($file, 'rb');
fpassthru($f);
fclose($f);
exit;
EDIT: If you are using any sessions_code, it is a good idea to end the session before starting the file dump process. I have updated my example to reflect this.