Single document, multiple filetypes for download: how to manage?
Question
I want to upload/attach several documents to a book node. Each document will be offered in a number of file formats, for example:
- Report2010.pdf
- Report2010.rtf
- Report2010.doc
- Agreement11.pdf
- Agreement11.rtf
- Agreement11.doc
Given this, in order to:
- Offer a sensible upload interface (like FileField) that allows an unlimited number of files to be uploaded.
- Present these files for download, for example:
Is there a robust way to relate the different file formats for each document to each other? By robust, I mean something that (for example) doesn't rely on the user naming the files in a particular way for it to work.
Solution 3
The Fieldgroup module seems to do almost everything I need: for each document, I create a group which has a filefield for each file type (PDF, DOC, RTF). It doesn't solve the requirement to allow unlimited files, but the workaround would be to create a number of groups that would reasonably cater for most scenarios.
OTHER TIPS
node-[type].tpl.php
$fields = array('field_reports', 'field_agreements'); // you should to create 2 fields for different filenames
$items = array();
foreach($fields AS $field){
$exts = array();
foreach($node->{$field} AS $file){
// delete real extension from file name
$filename = explode('.', $file['filename']);
$ext = array_pop($filename);
$exts[$ext] = l($ext, $file['filepath']);
$filename = implode('.', $filename);
}
ksort($exts);
$items[] = t('!filename - download as: !links', array('!filename' => $filename, '!links' => implode(', ', $exts)));
}
print theme_item_list($items);
Hovewer, this code must be in template.php in phptemplate_preprocess_node function.
You can use
http://drupal.org/project/mimedetect
to ensure the files have the correct mime type, and then
http://drupal.org/project/filefield_paths
http://drupal.org/project/file_aliases
http://drupal.org/project/token
to rename them based on file values
You should make a custom CCK formatter (start with filfield_formatter.inc as example) to output the files the way you want without hacking up your template files.