3

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:

  1. Offer a sensible upload interface (like FileField) that allows an unlimited number of files to be uploaded.
  2. 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.

0

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.

| improve this answer | |
  • Thanks for the response, however the example file names I gave were only examples. In practice (for my requirements) the files could have any name, and can't be categorised into topics like agreements or reports (there needs to be an unlimited number of documents, each of which need to be offered in an rtf, pdf or doc file format). Sorry if this wasn't clear. – Daniel Nitsche Apr 10 '11 at 5:02
0

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

| improve this answer | |
  • How does this solve the OP's problem? – cherouvim May 18 '12 at 10:25
0

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.

| improve this answer | |
  • Did you use fieldgroup or field_group? – cherouvim May 18 '12 at 10:27
0

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.

| improve this answer | |

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.