<?
/*
Copyright (c) 1999 Marcel Lemmen
       E-mail: lemmen@support.nl
All  rights  reserved.  

This code provided "As Is" with no warrantees  express or implied.
The author and contributors are not liable for anything good or bad
that results from your use of this code.

You are free to distribute this for free provided this notice is included.
Please forward fixes/enhancements to the
author for inclusion in the next revision.

Usage: 
Replace $files with the original with your files.
Replace $filenames with the filename people see when 
downloading (CAN be different then file's!!!)
Replace $URL with your directory or the other URL.

That's all!!!

*/

$files=array('file1.zip','file2.zip');
$filenames=array('File1.zip','File2.zip');
$url="/home/lemmen/public_html/data/";
/* When the files are on another server, use the
whole address (http://www.server.com/dir/) in stead of /home/lemmen... */

$referer=ereg_replace("\?.","",$HTTP_REFERER);
$thisfile="http://$HTTP_HOST$PHP_SELF";

if ($referer!=$thisfile)
  for ($i=0;$i<count($files);$i++)
  echo "<P><A HREF=\"$PHP_SELF?$i\">",$filenames[$i],"</A>\n";

else {
        $i=$QUERY_STRING;
        $total=$url . $files[$i];
        Header ("Content-Type: application/octet-stream");

        Header ("Content-Length: ".filesize($total));
        Header("Content-Disposition: attachment; filename=$filenames[$i]");

        readfile($total);
}
?>
