[ale] apache problem
John Heim
john at johnheim.net
Thu Jan 13 13:27:23 EST 2011
Yup. I ended up redirecting downloads to a php script which returns a 403
error if the user has downloaded another document within the last 3 seconds
or if they've already done more than 1000 downloads. If not, it ships them
the document.
----- Original Message -----
From: "Mike Harrison" <cluon at geeklabs.com>
To: <neal at mnopltd.com>; "Atlanta Linux Enthusiasts" <ale at ale.org>
Sent: Wednesday, January 12, 2011 2:07 PM
Subject: Re: [ale] apache problem
>> 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.");
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
More information about the Ale
mailing list