<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.5">
</HEAD>
<BODY>
Yeah, that sounds familiar. The real booger was figuring out for each browser what it wanted to see in the headers for those various file types. <BR>
<BR>
On Wed, 2011-01-12 at 15:07 -0500, Mike Harrison wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
> It's a moderate booger to write the thing that spits back the file
> inline, since we might have .pdf files, .html files, text files, and I
> recall we had to do content headers appropriately.
This is fairly easy to do in PHP, and I expect other languages as well.
This is the two fragments from a bigger program that demonstrate a method.
#FRAGMENT 1
$file_extension = strtolower(substr(strrchr($filename, "."), 1));
switch ($file_extension) {
case "pdf":
$ctype = "application/pdf";
break;
case "csv":
$ctype = "application/text";
break;
case "xls":
$ctype = "application/vnd.ms-excel";
break;
default:
$ctype = "application/force-download";
}
#FRAGMENT2:
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"" . basename($as) . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . @filesize($filename));
# set_time_limit(20);
ob_clean();
flush();
@readfile("$filename") or die("File not found.");
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>