Skip to main content

Display file attachment information in Drupal

Here's a code snippet for Drupal to add filefield data to any node or block.

Basically this is used to pull information from a CCK filefield.

<?php

function downloads_files($nid) {
 
$node = node_load(array('nid'=>$nid));
 
$output_title = $node->title;
 
$output_file_url = $node->field_pdf_file[0]['filepath'];
 
$file_size = $node->field_pdf_file[0]['filesize'];
 
$output_file_size = format_size($file_size);
 
 
 
  return
'<a href="/'.$output_file_url.'">'.$output_title.' ('.$output_file_size.') <br /> <strong class="more">Download</strong></a>';
}

?>

<ul class="downloads">
   <li><?php print downloads_files('154'); // we add the node id of the node where the file was uploaded to ?></li>
</ul>

Post new comment

The content of this field is kept private and will not be shown publicly.