How to Automatically Start a Download in PHP?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

What code do you need to add in PHP to automatically have the browser download a file to the local machine when a link is visited?

Here is an example of sending back a pdf.

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
readfile($filename);

Leave a comment

Share This Post

RSS Wordpress News