[ale] apache problem

Mike Harrison cluon at geeklabs.com
Wed Jan 12 15:07:12 EST 2011


> 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.");



More information about the Ale mailing list