0

So I wanted to add date alongside the size of the file in filefield table of files so I added this snippet to templates.php

function mytheme_file_formatter_table($variables) {
  $header = array(t('Attachment'), t('Size'),t('Upload Date and Time'));
  $rows = array();
  foreach ($variables['items'] as $delta => $item) {
    if ($item['timestamp'] == 0) {
      $item['timestamp'] = 1234567890;
    }
    $rows[] = array(
      theme('file_link', array('file' => (object) $item)),
      format_size($item['filesize']),
      format_date($item['timestamp'],'custom','Y/m/d - g:i'),
    );
  }
  asort($rows);
  return empty($rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));
}

It works just fine but I also need to show the download count of the file, and I have no clue on how to do this. Thanks

1

There's many ways to get this working depending on the type of file access you want.

File Download Count - counts download when it's really been downloaded and not just clicked, new so I can't post more than 2 links. Google this.

Public Download Count - track public files

Download Count - track private files

  • Thank you for the help, I stumbled upon these modules myself while googling around, but they are not really that helpful in my case, File Download Count, is just an API and doesn't do anything basically, using download count I managed to show the downloaded time in Generic file display, bu as you can see in my question, I want to be able to do it in table of files while showing other parameteres as date, filesize and file name – Sohail Aug 13 '14 at 11:16
  • There's another way, but you have to create a custom module. I recommend adding a new field to the content type you want to track and have that store integer count of the # of times that particular file has been clicked. That's how I did it on my past websites. Increment the count field and have that field display on the table using Views. Wonder why you're not using Views to create the table? – Frances Naty Go Aug 15 '14 at 7:30
  • Thanks for the tip, yea maybe I go with views way, but since I also do other things on that table of files such as logging previous entries and letting users with proper permission to do actions on that, it's gonna be quite hard to achieve it this way, I already done this, it's only the download count thing that remains, but thanks anyway – Sohail Aug 15 '14 at 19:59
0

You can also try the Track da files module. It does work for tracking access to both private or public files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.