How to display metadata about uploaded file(s) in my theme?

I use Omeka 2.4.1 and I want to display in my public theme the info about uploaded file(s) such as : format metadata, file history, id3 metadata.

Is there a way to make that information public ?

You can do that by editing the theme, yes.

Most of that information is available by calling metadata on the file object. If you look at how we display that information on the admin theme, it should be pretty clear how to get at what you want and put that into your public theme.

Thank you for your quick answer.

Perharps I miss something, because if I try to simply copy a bit of information like the MIME type in my theme (/show.php) like :

<p><?php echo metadata('file', 'MIME Type'); ?></p>

it doesn’t work.

Maybe I have to do something more?

Is this the items/show or files/show view?

All this metadata is on the File, not the Item, so if you’re looking to show it on the item’s page, you’ll have to get the file first. Usually, themes loop over the files set to an item:

set_loop_records('files', $item->Files);
foreach (loop('files') as $file):
    // your display for each file
    // metadata($file, 'some metadata') will work here
endforeach;

That’s exactly what I was looking for.
It works perfectly.
Thank you!

Another question :

Is there a way to get only some specific id3 metadata values, such as, resolution_x and resolution_y ? Because I don’t want the whole list but only some information. I can’t figure out how to specifically access this level of detail.

This is still for the items/show page.

Thanks.

This bugged me and I can’t find docs on the “Omeka way” to do it, so I came up with this:

foreach (loop('files', $item->Files) as $file):
     $json = json_decode($file[metadata], true);
foreach($json['audio'] as $f=>$v) {
	$va='';
	if(is_array($v))
	   $va="<pre>". print_r($v, true). "</pre>";
	echo "$f --> $v $va<br>";
}
endforeach;

This gives me some output like:

dataformat --> mp3
channels --> 1
sample_rate --> 44100
bitrate --> 192043.96645642
channelmode --> mono
bitrate_mode --> vbr
lossless -->
encoder_options --> VBR
compression_ratio --> 0.27217115427497
streams --> Array
Array
(
    [0] => Array
        (
            [dataformat] => mp3
            [channels] => 1
            [sample_rate] => 44100
            [bitrate] => 192043.96645642
            [channelmode] => mono
            [bitrate_mode] => vbr
            [lossless] => 
            [encoder_options] => VBR
            [compression_ratio] => 0.27217115427497
        )
)

I’ll walk you through:

foreach (loop('files', $item->Files) as $file): << you already know how to do this, go through each file for the item you’re working with.

$json = json_decode($file[metadata], true); << The “[metadata]” array in the file object is where the metadata lives – it is in json format. json_decode() with true as second parameter turns the json string into a php array.

foreach($json['audio'] as $f=>$v) << the “audio” part of the array is where the ID3 data is kept. For our purposes here, we are going to just loop through all the values so we can see what’s available.

if(is_array($v)) {$va="<pre>". print_r($v, true). "</pre>";} << some of the values are themselves arrays, so I just simply made it also show those.

From the output we can now see that we can target whatever we want, e.g., $json[audio][streams][0][bitrate] will show us the bitrate for the 1st stream in the MP3 file.

Again, this way of doing it is dumb and I’m sure Omeka has built-in ways to do this, but I can’t find the documentation. file_id3_metadata isn’t right because that gives an HTML list of all the ID3 info.

You more or less have it: there is no “Omeka way” to do this really. We just store the getID3 data as a json_encoded array, so if you want to display a certain part of that, I’d recommend you just do a simple isset() check for the key you want to display and access it that way.