0

Does anyone know how I can count how many times a pdf has been downloaded from my site? Maybe someone has a php script or something that does this?

Thanks!

Dave

5
Contributors
8
Replies
9
Views
9 Years
Discussion Span
Last Post by daviddoria
0

I think it would be better to move this thread to PHP Forum, in order to get more response from others.

0

peter_budo: that looks cool, but seems like WAY overkill for what i'm trying to do

if this can indeed be done with a simple php script, can one of the admins please move this to php as mexabet suggested?

Thanks,

Dave

0

I have 0 php experience but this doesn't seem like it would be that hard to do. Just have it read the last 3 characters of the file that was downloaded and if all the characters are pdf then you accumulate some variable that keeps track of number of downloads.

0

That is not over kill, it standard tool use for monitoring website activity and utilizing variety of data in nice neat tables and graphs

Anyway post been move to PHP

0

I use this script for downloading pdfs from an ftp site because they are secure files, you can just delete this part(ftp://username:password@servername) out and just use $docname to pull a file from the file system. Then all you need is some type of database connection which manages your statistics and you're all set:

<?
$docname = "/path/to/file.pdf";
$docsize=@filesize("ftp://username:password@servername$docname");

if($docsize == 0 || $docsize == -1)
{
	header("location: http://" . $_SERVER['SERVER_NAME'] . "/index");
	exit();
}
else
{
	$fp=fopen("ftp://username:password@servername$docname", "rb");
	header("Pragma: ");
	header("Cache-Control: ");
	header("Content-type: application/pdf");
	header("Content-Disposition: attachment; filename=\"" . basename($docname) . "\"");
	header("Content-Transfer-Encoding: binary");
	header("Content-length: $docsize");
	fpassthru($fp);
	//header("Connection: close");
}
?>
0

One small adjustment: the return is not correct if the file is not found. adjusted the if statement.

<?
$docname = "/path/to/file.pdf";
if(!$docsize=@filesize("ftp://username:password@servername$docname"))
{
	header("location: http://" . $_SERVER['SERVER_NAME'] . "/index");
	exit();
}
	
$fp=fopen("ftp://username:password@servername$docname", "rb");
header("Pragma: ");
header("Cache-Control: ");
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"" . basename($docname) . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-length: $docsize");
fpassthru($fp);
//header("Connection: close");
?>

Sorry about that, as you can imagine I had to simplify the script a bit before posting. It works fine now.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.