get filename for item

Hi. I'm trying to get the filename for an item to pass to a url. I did this in the 1.5.x software but can't figure it out in 2. I'm using '<?php echo metadata('file', 'Filename'); ?>' but get "A current file variable has not been set to this view" . I need the txt for the filename "13fd7ca0146722e28bd2ea27dcb4d9cb.pdf" no marup. Thanks, Adam

It depends a little on exactly what page you are on (show vs. browse, e.g.), and possibly where in the page your -- especially if you are in a loop over files for an item. If you aren't, that's what gives the message you see.

In general, though, this will get the file names:

<?php
<?php
    if (!$item) {
        $item = get_current_record('item');
    }
    $files = $item->Files;
    foreach($files as $file) {
        echo metadata($file, 'filename');
    }

?>

?>

Hi Patrick and thanks. This next question is more php related, and I know your busy. We want to use pdf.js to instead of the Google Doc Viewer mainly because some of the pdf's are large and the GDV times out. The code I'm using is adding three spaces into the URL, aside from that it's working.

'<?php echo'<iframe width=100% height=800 src="http://128.83.78.208/apps/web/viewer.html?file=http%3A%2F%2F128.83.78.208/ford_omeka/files/original/'; ?>
<?php
if (!$item) {
$item = get_current_record('item');
}
$files = $item->Files;
foreach($files as $file) {
echo metadata($file, 'filename');
}
?>
<?php echo '"></iframe>'; ?>'

The page is at http://128.83.78.208/ford_omeka/items/show/1449 if you click "More Info" you see the white space. I'm looking into url encode to try and fix that. Thanks

I'm hoping that you've found the solution -- when I go to that page I'm not seeing the "More Info" link, and so I'm being hopeful that it's all good.

If not, I'd guess the whitespace comes in between the different <?php parts

Hi Patrick. Sorry, I did finally get it going. We're testing two different pdf viewers one is pdf.js, the other a variation of the Google Doc Viewer. I'll put the code that worked for both below and switch them both on. I like the pdf.js viewer, it has a lot of features, and is really customizable. Maybe I'll try to brew up a plugin for it.

pdf.js

'<h3><?php echo __('View File'); ?></h3>
<?php echo'<iframe width=100% height=800'; ?>
<?php if (!$item) {$item = get_current_record('item');} $files = $item->Files; foreach($files as $file) {echo 'src="http://128.83.78.208/apps/web/viewer.html?file=%2Fford_omeka%2Ffiles%2Foriginal%2F', metadata($file,'filename');} ?>
<?php echo'"></iframe>'; ?>'

Alt Google Doc's Viewer

'<h3><?php echo __('View File'); ?></h3>
<p>It may take a moment to load into the viewer.</>
<?php echo '<?php if (!$item) {$item = get_current_record('item');} $files = $item->Files; foreach($files as $file) {echo metadata($file,'uri'); } ?><?php echo '" id="embedURL">'; ?>
'
http://128.83.78.208/ford_omeka/items/show/1449

and thanks for your help, I couldn't have moved forward without it.