How do I change the displayed filename, when I am looking at the node? If somebody uploads doc1.pdf, filefield paths renames it to agreement.doc, and I want it displayed as agreement.doc, how do I accomplish this? Currently, it shows as doc1.pdf. Should I adjust my node-nodetype.tpl.php? Or is there something easier?

Comments

light-blue’s picture

After a little research, this was easy. I copied and pasted theme_filefield into my own module as follows. Is there a better way?

function phptemplate_filefield($file) {
  //dpm($file);
  if (user_access('view filefield uploads') && is_file($file['filepath']) && $file['list']) {
    $path = ($file['fid'] == 'upload')
            ? file_create_filename($file['filename'], file_create_path($field['widget']['file_path']))
            : $file['filepath'];

    $icon = theme('filefield_icon', $file);
    $url = file_create_url($path);
    $parts=explode('/',$file['filepath']);
    $part=array_pop($parts);
    $desc = t('!name (original filename: !orig)',array('!name'=>$part,'!orig'=>$file['description']));
    return '<div class="filefield-item">'. $icon . l($desc, $url) .'</div>';
  }
  return '';
}
Deciphered’s picture

Category: support » feature

Agreed, this is definitely a must, I came across the same issue myself not long ago.

Will look into a better solution.

Cheers,
Deciphered.

vaporizers’s picture

I ended up theming node-nodetype.tpl.php and it worked out very well.
But really... this functionality should be built in...

neRok’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Closing old issue. This sounds like a feature that is in 6.x and 7.x, maybe it was added to 5.x at some stage?