If you provide a free download file then you might want to know how many times it has been downloaded by your user. Setting this feature in drupal is no rocket science, just that you need to know what to do.

Drupal has 2 different download system that you can use, one is the private download method and the other is the public download method. This article is going to discuss only the public download method.

To count the download count in drupal you need the Public Download Count module, you can download the module at its drupal.org project page.

After you download the module, you need to extract, upload and enable the module as any other drupal module.

Now, after you done installing the module, if you are using cck filefield as many of us will be, you need to point the link url to the module so every click to download the file will be recorded by the module.

To point the download link to the public download module you need to do this in your template or module

// for this example we are going to print the link based on the information of :
// the cck filefield field is field_file
// the code is going to be used in node.tpl.php thus $node is available for us to use

print _filter_pubdlcnt(l('Download', $node->field_file[0]['filepath']), $node->nid);

Now we explain what is going on on the code above

_filter_pubdlcnt() is the function that calls the public download module for recording the links

l() is the drupal function to create a link

'Download' is the link text going to be

$node is the data that we can use to get the file path, in this example we are using the code on node.tpl.php thus the $node is available for us to use, in other cases you might want to search what is the variable /data that contain the actual filepath

field_file[0]['filepath'] this is the cck filefield stored array for filepath and field field_file, most likely you will have a different stored array. To determine your cck stored array, you can do print_r($node, TRUE) in your node.tpl.php and look for the array with ['filepath'] key.

$node->nid this is the node id number (nid) that we pass to the module for counting

Now if you have done the linking to the module, you can try clicking the link that you just made and then go to the module counting report to see the download count.

The module counting report page is at /admin/reports/pubdlcnt

Enjoy your counting.....