I'm trying to write a secure downloads script for zip files, and have run into a snag. Here's my code so far:
$file = $result[itempath];
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
It's finding the file and trying to do something but all it's doing is printing out a bunch of gobblydegook to the screen. From my searching around and reading, code like this is supposed to make the file itself actual download. So...what am I doing wrong? I've tried a bunch of different variants of the above code from different sites, but it's all the same thing...just a bunch of gibberish to the screen.