Here's a small function that will allow you to force a file download.
PHP:
-
/**
-
* Force a file download via HTTP.
-
*
-
* File is required to be on the same server and accessible via a path.
-
* If the file cannot be found or some other error occurs then a
-
* '204 No content' header is sent.
-
*
-
* @param string $path Path and file name
-
* @param string $name Name of file when saved on user's computer,
-
* null for basename from path
-
* @param string $type Content type header info (e.g., 'application/vnd.ms-excel')
-
* @return void
-
* @access public
-
*/
-
/* public static */ function download($path, $name = null, $type = 'binary/octet-stream')
-
{
-
echo 'File download failure: HTTP headers have already been sent and cannot be changed.';
-
exit;
-
}
-
-
exit;
-
}
-
-
-
exit;
-
}
Very easy to use, too! Here are some examples of how you might call the function:
PHP:
-
download('./myfile.txt');
-
-
download(__FILE__, 'a file for you.php');
-



