<?php
$counterfile = "letolt.txt";

// Download Function

function download($url) {
	header("Location: $url");
}

// Check for link validity
if($_GET['id'] == "") {
	$_GET['id'] = '/';
	download($_GET['id']);
	exit;
} else {
	// Download File
	download($_GET['id']);
}

// Count Hits

$opencount = fopen($counterfile,"r") or die("Couldnt open");
echo "opencount=" . $opencount;
echo "counterfile=" . $counterfile;
$currentcount = @fread($opencount, filesize($counterfile)) or die("Couldnt read");
echo "currentcount=" . $currentcount;
fclose($opencount);

$newcount = $currentcount;
++$newcount;
echo " newcount= " . $newcount;
$opennewcount = @fopen($counterfile,"w") or die("Couldnt open for editing");
fwrite($opennewcount, $newcount) or die ("Couldnt write");
fclose ($opennewcount);


?>
