Change file extension on upload to panel

I wanted to rename all files of a particular type (extension) to another when upload.

// $uploaded_file = 'my-presentation.pptx'

// where $uploaded_file is whatever file user has just dropped/added to panel, in the case of this example, a PowerPoint presentation with filename 'my-presentation.pptx'.

if( $uploaded_file->extension() === '.ppt' ) {
  $uploaded_file->rename('my-presentation.pps');
} elseif { $uploaded_file->extension() === '.pptx' {
  uploaded_file->rename('my-presentation.ppsx');
}

How do I hook into the file upload behaviour and perform this rename every time a file with a matching extension is uploaded?

Many thanks in advance.

Nevermind. I just found the answer in the docs: https://getkirby.com/docs/developer-guide/advanced/hooks

I have an additional problem. The code below solves my original question, except it only can modify the file name excluding the extension.

kirby()->hook('panel.file.upload', function($file) {

  try {
    if ( $file->extension() === 'ppt') {
      $new_filename = $file->name() . '.pps';
      $file->rename($new_filename, true);
    } elseif ( $file->extension() === 'pptx') {
      $new_filename = $file->name() . '.ppsx';
      $file->rename($new_filename, true);
    }
    echo 'The file has been converted to a slideshow';
  } catch(Exception $e) {
    echo $e->getMessage();
  }

});

Question: How do I change the file extension, not the file name?

Use a PHP function, I think Kirby avoids the change of a filetype.
You want to change a mime type, what from the view of Kirby is not a rename!