Downloads
When I was setting up my new website, using Drupal, I wanted to have a page per project, like the one you're reading now. I wanted to attach the programs to the page, and have it show the MD5Sums and download count. The builtin upload.module didn't do that. Other modules did, but added more complexity, such as making each download its own node, so I wrote downloads.module.
On install, it creates a downloads_data table, and whenever a page is viewed, it checks to see if there are attachments listed which aren't in the table yet. If so, it calculates the MD5Sum and adds them. Either way, it presents the extra info in an array that the theme can use to add to the attachments table. For the counting, it hooks onto the file download hook, and updates the database.
Theming
Here's a snippet from my node-content-program.tpl.php file, showing how to use the extra variables:
<?php
$files = $node->files;
$header = array(t('File'), t('Size'), t('MD5Sum'), t('Downloads'));
$rows = array();
foreach ($files as $file) {
if ($file->list) {
$fid=$file->fid;
$dlinfo=$node->dls[$fid];
$href = check_url(($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))));
$text = check_plain($file->description ? $file->description : $file->filename);
$rows[] = array(l($text, $href), format_size($file->filesize), $dlinfo->md5, $dlinfo->count);
}
}
if (count($rows)) {
echo theme('table', $header, $rows, array('id' => 'attachments'));
}?>Most of that is just copied from the existing table creation code. The new bit is
<?php
$dlinfo=$node->dls[$fid];
?>and the use of that to add the extra two columns to
<?php
$rows[]
?>(My site adds an icon next to the filename, based on the filemime, but I cut that out from the above to keep it simple.)
Drupal versions
There's now a Drupal 5 version, with a bugfix and a .info file. Use downloads 0.3 for Drupal 4.7, or downloads-5.x-0.4 for Drupal 5.
| File | Size | MD5Sum | Downloads |
|---|---|---|---|
| downloads-0.3.tar.bz2 | 1.27 KB | 0e847231c263dde9daff075010c2bfe3 | 85 |
| downloads-5.x-0.4.tar.bz2 | 1.63 KB | 8f55b102d1d6728dc6a445a7462e3bc9 | 13 |