by prettyscripts on 2007-11-27 22:42:37 • Leave a comment »
a general php code to download any type of file:
PHP:
header("Content-Type: application/octet-stream"); | |
header("Content-Length: " . filesize($filename)); | |
header("Content-Disposition: attachment; filename=\"$filename\""); | |
readfile($filename); |
content-type defines the type of file being sent. application/octet-stream is used for any kind of files.
content-length indicates the size of information. this is to let browser know how much data to download in advance and ensure
content-disposition is used to suggest the file name to be saved. the filename should have the correct extension so that the browser knows the default application associated with this extension.