Hello out there!
I use the following download counter to count the files that I have avaliable for download on my website:
download.php:
$extension = ""; //leave this blank if you have various extensions.
$counterdir = "counters/"; //change this if you want other directory for the counter files.
$textfont = "Verdana,Arial"; //text font for the error msg
if (file_exists("$get$extension"))
{
header("location: $get$extension"); // download the file [download.php?get=name_of_file]
$file = fopen("$counterdir/$get.txt","r"); // download counter
$count = fread($file, 100);
$countplus = ($count + 1);
fclose($file);
$fileb = fopen("$counterdir/$get.txt","w");
fwrite($fileb, $countplus, 100);
fclose($fileb);
}
else echo "<font face=$textfont size=2>";
echo "<center>
The file [$get$extension] is not available for download.
";
echo "Please contact the web administrator";
?>
I call this script more or less like this in a href: download.php?get=myfile.pdf
Now, I would like to add this following script that forces the users' browser to download the files (usually .pdf files) instead of opening them in the browser window:
forcedownload.php:
<?
$path = "myfolders/".$HTTP_GET_VARS['filename'];
$file = basename($path);
$size = filesize($path);
header ("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
header("Content-Length: $size");
readfile($path);
?>
I call this script in a href like this: forcedownload.php?filename=myfile.pdf
Both scripts work fine individually but how do I combine them so that they both work at the same time? So that by clicking a link, the file is forced to be saved and counted at the same time?
Thanks in advance. :-)