Panel Hook & Set

Hey all,

I’ve created a panel hook for file uploads, I’m trying to assign a value to an empty page field when a file is uploaded.

For example; If I uploaded a video file, I’ll get the video duration through an existing hook. I’m wanting to set that duration as a meta field value to use else where in the site.

I’ve tried using the following which doesn’t seem to work, can anyone shed any light on why this wouldn’t work?

kirby()->hook('panel.file.upload', function($page) {
     page('PAGE TITLE HERE')->set('test', 'testing123');

Am I missing something?

Cheers :slight_smile:

You need to use the $page->update() method, I’ve used a similar hook for fetching audio meta data using the getID3 library:

kirby()->hook('panel.file.upload', function($file) {
    if ($file->extension() === 'mp3') {
        $getID3 = new getID3();
        $info   = $getID3->analyze($file->root());

        $audioData = [
            'filesize' => $info['filesize'],
            'playtime' => $info['playtime_string']

        $page = $file->page();


Don’t know why I didn’t think of that, I’ve used it countless times too :joy:

Cheers @pedroborges