Jump to content

Tracking File Downloads


Recommended Posts

I'm trying to track which files have been downloaded by which users.

 

I'm using this action hook to track the downloads: http://docs.whmcs.com/Hooks:FileDownload

 

Here's the code I have for my action hook:

 

<?php
add_hook("FileDownload",0,"track_FileDownload","");

function track_FileDownload($vars)
{
   logactivity("File Downloaded");
}
?>

 

Right now it's displaying this in my activity log:

 

File Downloaded

 

But what I would like is for the log to also display the title of the file that was downloaded, like this:

 

File Downloaded - Name Of File

 

Does anyone know how to do this or if it's possible?

Link to comment
Share on other sites

there is no values inside $vars passed to function but we can access $_REQUEST to get file ID and using it we can get the information of that file, the following code will give you what you need:

 

<?php

# Track Files Downloaded
function hook_trackFilesDownloaded($vars){

   $fileID = intval($_GET['id']);

   if ($fileID!=0){

       $getFileInfo = full_query("SELECT `title` FROM `tbldownloads` WHERE `id`='{$fileID}' LIMIT 1");
       $getFileInfo = mysql_fetch_assoc($getFileInfo);

       logActivity("File Downloaded - " . $getFileInfo['title']);

   }
}
add_hook("FileDownload", 1, "hook_trackFilesDownloaded");

Link to comment
Share on other sites

use the following one and it will add the clientID to log message only if the client is logged, try it

 

<?php

# Track Files Downloaded
function hook_trackFilesDownloaded($vars){

   $fileID = intval($_GET['id']);
   $userID = $_SESSION['uid'];

   if ($fileID!=0){

       $getFileInfo = full_query("SELECT `title` FROM `tbldownloads` WHERE `id`='{$fileID}' LIMIT 1");
       $getFileInfo = mysql_fetch_assoc($getFileInfo);

       $logText = '';

       $logText .= "File Downloaded - " . $getFileInfo['title'];

       if ($userID!=0){
           $logText .= " - User ID: " . $userID;
       }

       logActivity($logText);

   }
}
add_hook("FileDownload", 1, "hook_trackFilesDownloaded");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated