Thursday, 23 October 2008

Force Download via. HTTP Headers

I've been playing a little with php headers recently, and if you've ever wanted to force a downloaded via. HTTP without reading the 14563 page specification document, then check this out.

 header('Content-type: application/zip');
 header('Content-Disposition: attachment; filename="File.zip"');
 readfile('File.zip');


Content-type - Defines what the browser is expecting to serve as content
Content-Disposition - Specifies the type and filename of the download.
readfile - basically sends the content to the output buffer and forces a download dialog.

have fun!

No comments: