Reputation: 2113
I have a php site am trying to track number of times my downloads get hit using the following code:
//update download count
update_attachment_counter($attachment);
// We'll be outputting a PDF
header ( 'Content-Type: application/pdf' );
header ( 'Content-Disposition: inline; filename="fileName.pdf"');
header('Content-Length: ' . filesize($attachment));
readfile ( $attachment );
die ();
I am seeing my counters go up multiple times per download. My attachments are anywhere from 2 to 30MB in size. Does it make since that I am seeing multiple requests per download? How do I only track each download once?
Upvotes: 1
Views: 77
Reputation: 2113
Due to the large file size, I am getting partial download requests. By checking for HTTP_RANGE I was able to determine if it was the original request or the partial request:
if(!isset($_SERVER['HTTP_RANGE']))
{
.... update counter
}
See using php to download files, not working on large files?
Upvotes: 1