whenpenguinsattack.com

Sunday, February 26, 2006

File downloads in PHP

By Justin Silverton

This is a simple code snippet. It will allow you to force the web-browser that is currently viewing your script to come up with a file-download box (and the a file on your system can be downloaded).

Here is the code:

//so only the data from the headers is sent
ob_start();
//dispable caching
header ("Cache-Control: must-revalidate, pre-check=0, post-check=0");
header ("Content-Type: application/binary");
header ("Content-Length: " . filesize($export_long_name));
header ("Content-Disposition: attachment; filename=yourfile.ext");
readfile($export_long_name);

A list of of mime types can be found Here

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home