<?php
/*
* Downloadcounter Kontrollscript
* Author Dirk Hoeschen (hoeschen at feenders.de) 
*/

$path="files/";

// hole dateinamen aus variable f
$f = strip_tags($_GET["f"]);
$adcheck = strip_tags($_GET["ird"]);

if($adcheck == "")
{
	header ("HTTP/1.1 301 Moved Permanently"); 
  	header ("Location: http://WinLaunch.bplaced.net"); 
	exit(0);
}
else
{
	if ($f!="") {
		// ganzes verzeichnis lesen
		$dir_handle = @opendir($path) or die("Unable to open ".$path);
		
		while ($file = readdir($dir_handle)) {
			
			//found file but it's not renamed yet
			if ($file==$f) { 
				rename($path.$file,$path."0:".$file);
				$file = "0:".$file; 
			}
			
			// datei in array splitten
			$fparts = split(':',$file);
			
			if ((count($fparts)>1) && ($fparts[1]==$f)) {
				// counter+1, datei umbenenenn
				$dlcount = intval($fparts[0])+1;
				$newfilename= $dlcount.":".$f;
				rename($path.$file,$path.$newfilename);
				break;
			}  
		}
		
		// datei mit dem ursprünglichen namen ausgeben
		if ($newfilename!="") {
		header('Content-type: application/zip');
		header('Content-Disposition: attachment; filename="'.$f.'"');
		header("Content-Transfer-Encoding: binary");
		header("Content-Length:" . filesize($path.$newfilename));
		
		readfile($path.$newfilename);
		}
		
	}
}
?>