Counting file downloads


Applies to Web File Share version (260213)

To keep track of the files' download count, please follow these steps:

<?php

 

$fieldId = XXXX; //set here the ID of the metadata field that will be holding the downloads count

 

/*-----------------------------------------------------------------*/

 

global $metadata, $db;

$data = unserialize($data['data']);

$metaFileInfo = $metadata->files->getByPath("*", $data['full_path']);//get file metadata record

 

if (!$metaFileInfo['id']) {

                $id = $metadata->files->addFile($data['full_path']);//add file metadata record if not found

                if ($id) {

                                $metaFileInfo['path'] = $data['full_path'];

                                $metaFileInfo['id'] = $id;

                }

}

 

$rs = $metadata->get($metaFileInfo['id'], array($fieldId));//get current download count

 

$downloads = $rs[0]['val'];

if (!$downloads) {

                $downloads = 0;

}

$metadata->set($metaFileInfo['id'], $fieldId, $downloads+1);//increment the download count

The "download.php" script will execute each time a user downloads a file, and it will increment the value it finds in the file's "Downloads" metadata field. You can reset the count at any time, by editing the value from the Metadata menu.

Being a metadata field, you can also display it as a column in the file list view, to have a quick view over how many time the files were downloaded.

 



Article ID: 596
Created On: Thu, Mar 6, 2014 at 7:29 AM
Last Updated On: Tue, Nov 21, 2017 at 4:07 PM
Authored by: KB Admin01 [[email protected]]

Online URL: https://kb.quikbox.com/article.php?id=596