Download Photos and count downloads

plungerman
plungerman's picture

Joined: 2006-10-19
Posts: 7
Posted: Mon, 2007-05-28 14:55

greetings,

i am developing a module that will track the number of downloads for each user and limit access depending on the number of "credits" you have left in your account. that is, you will have, for example, 500 credits, which allows you 500 downloads. for each download, we will deduct 1 from your account, and add one to the photos download count so that we can track statistics about each photo in the system.

the problem i am having is that different browsers seem to handle the download event differently. i basically copied DownloadItem.inc from core and added our stats counter just above the function sends the header info to the browser:

// Increment the download count for this item
GalleryCoreApi::requireOnce('modules/statistics/classes/StatisticsDownloadHelper.class');
$download_helper = new StatisticsDownloadHelper;
list($ret, $item) = $download_helper->incrementDownloadCount($data['id']);
if ($ret) {
return $ret;
}
$phpVm->header('Cache-Control: no-cache, must-revalidate');
$phpVm->header('Expires: Mon, 11 Sep 2001 16:20:00 GMT');
$phpVm->header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$phpVm->header('Content-type: "application/octet-stream"');
$phpVm->header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
$stats = $platform->stat($data['derivativePath']);

IE6 and IE7 seem to send a request to the web server each time you click on the download link, while mozilla based browsers seem to buffer the information about the download and just present the client with a download dialog box, rather than requesting to the web server the download view, which is:

main.php?g2_view=statistics.DownloadItem&g2_itemId=46

thus, DownloadItem will register the downloads for each IE6/7 client requests, while mozilla browsers like firefox will only register the first request for download and nothing more after that.

can anyone shed some like on this subject? perhaps i must introduce some other element in the process to force the browser to go throught the entire DownloadItem view.

apache 2.0.55
mysql 4.21
gallery2.2
php4.3
centos 4

it might also have something to do with apache on windows vs apache on linux, since it was working for both IE and firefox an XP box with xampp 1.5.5 using apache 2.2.3.

thanks in advance,

steve

p.s. this is a module i am contributing to the community, if anyone needs just such a service, so hit me up if you want to help out.