Sending Files for Download with PHP


Force a file to be downloaded rather than displayed in the browser.

Source Code

$file = "example.pdf";
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments