Hi,
I need to return the archival file URLs (as in, http://example.com/archive/files/song.mp3) for audio files in certain item records but cannot seem to get to them. display_files_for_item() returns all kinds of extra info for the media player. I've tried a few other functions as well, but no luck so far.
Thanks,
Erin
(PS: working on integrating an A/V Flash wrapper into a new theme)
Hi Erin,
You can use the file_display_uri function to get the uri for a specific file object, assuming you have the file object somehow already. The following example would get all the files available on the view (items/show.php in this case) as an array, then echo the uri for each of those.
<?php
$files = get_files_for_loop();
foreach ($files as $file) {
echo file_display_uri($file);
}
?>
You can also just pass any $file object, using get_files.
These are functions we should document on our Theme API page, so I'll add a to-do to get this done.
Hope this helps, and would love to see that Flash wrapper when you're done!
Thanks Jeremy,
I tried it and got this error:
Invalid argument supplied for foreach()...
Here's the code I'm using for now, in which I first test for an image to use with lightbox and then test for the Sound item type (eventually, I will probably use mime types, but this should do the job in the meantime) for use with the flash wrapper and then if none of the above, I use the standard display_files_for_item()...
<?php
if (item_has_thumbnail())
{
echo '<p><em>Click the Image for Full Size</em></p>';
echo display_files_for_item(array('linkAttributes'=>array('rel'=>'lightbox[gallery]')));
}
elseif (item_has_type('Sound'))
{
echo '<script type="text/javascript">AudioPlayer.embed("audioplayer_1", {soundFile:"';
$files = get_files_for_loop();
foreach ($files as $file) {
echo file_display_uri($file);
}
echo'"});';
echo '</script>';
}
else
{
echo display_files_for_item();
}
?>
Nevermind.
Looks like this works (though I switched to a different media player that doesn't require the full absolute path)
foreach ($item->Files as $file) {
echo file_download_uri($file);}