Php headers/readfile issue

Have the following snippet working almost perfectly:


// Now the download is recorded, give the file:
$fileinfo = $db->get_row("SELECT filename FROM resources WHERE id='$dl'");
$filename = $fileinfo->filename;

$download_path = $_SERVER['DOCUMENT_ROOT'] . "/path/resources";
$dlpush = "$download_path/$filename";

// Test to ensure that the file exists.
if(!file_exists($dlpush)) die("I'm sorry, the file doesn't seem to exist.");
        


// Send file headers
header("Content-type: application/pdf");
header("Content-Disposition: attachment;filename=$filename");
header('Pragma: no-cache');
header('Expires: 0');

// Send the file contents.
readfile($dlpush); 

The problem is that the downloaded file is missing the “.pdf” at the end. Even though that is returned in the filename and dlpush variables. Adding it means the file is fine, but obviously I don’t want users to have to do that!

Any ideas?

TIA

Hmmm - scratch that. Now seems to be working. Very odd indeed!