<?php

$path_to_files = "./data/files";//path to the file upload folder 
$path_to_files_db = "./data/files.txt";//path to the files database

if($_GET['file']){
	$file = $_GET['file'];
	$content_file_db = file($path_to_files_db);
	$file_db = fopen($path_to_files_db, "w");
	foreach($content_file_db as $single_line){
		$single_line_arr = explode("|", $single_line);
		if($single_line_arr[0] == $file){
			$new_count = $single_line_arr[2] + 1;
			fwrite($file_db, $single_line_arr[0]."|".$single_line_arr[1]."|".$new_count."|\n");
		}
		else fwrite($file_db, $single_line);
	}
	fclose($file_db);
	

header('Pragma: private');
header('Cache-control: private, must-revalidate');
header("Content-type: application/force-download"); 
header("Content-Disposition: attachment; filename=".$file);
header("Content-Length: ".filesize($path_to_files."/".$file));

readfile($path_to_files."/".$file);

}

?>