DEFINE('DL_PATH',''); //Add trailing slash
isset($_GET['file'])?$rf = $_GET['file']:exit();
$path = DL_PATH . $rf;
if (file_exists(DL_PATH.$rf)) {
$fp = fopen('counter.php','r');
$count = fread($fp,4096);
fclose($fp);
$arr = json_decode($count,true);
$arr[$rf] = $arr[$rf]+1;
$fp = fopen('counter.php','w+');
fwrite($fp,json_encode($arr));
fclose($fp);
}
?>
if (file_exists(DL_PATH.$rf)) {
$fp = fopen('counter.php','r');
$count = fread($fp,4096);
fclose($fp);
$arr = json_decode($count,true);
echo "File $rf has been downloaded $arr[$rf] times so far";
}
?>