Display links to uploaded files of the current node wherever you want
Description
This snippet will extract information from the $file object so that you can display links to uploaded files of the current node practically anywhere you want and get them to look however you want. I find the default way that Drupal lists files at the bottom of the page to be pretty ugly, and sometimes I'd rather just have a simple link with my own specified anchor text than a big table with file sizes and what not.
Details
This snippet is meant to be used with some kind of template builder like Contemplate. You can also use it in your theme's template files like node.tpl.php and page.tpl.php. It's good to use it with Contemplate though because then you can easily remove the default file listings at the bottom of the node.
This snippet is meant for people whose sites depend heavily on file uploads and often times have multiple files uploaded to a single node.
<?php
$files = $node->files; // put the object into a simpler variable
$keys = array(); // initialize an array for the keys to go into
$keys = array_keys($files); // map the keys into another array
foreach($keys as $value){ // go through each key
$path = $files[$value]->filepath; // get the path for this file
$type = $files[$value]->filemime; // get the MIME type for this file
if($type == "something"){ // I like the anchor text to depend on the file type
$anchor = "something"; // you can make it whatever you want though
} else {
$anchor = "something else";
}
print l($anchor, $path); // make a link out of it
}
?>This is a pretty general snippet and you can customize it however you want. All it does is retrieve information from the file object. Things like the anchor text can be determined however you want it. You can even apply style information however you want. Note that you can get a full list of values available from the file object by using print_r($node->files).
