Reference

Guide

$file->rename()


$file->rename(string $name, bool $sanitize = true): Kirby\Cms\File

Parameters

Name Type Default Description
$name string
$sanitize bool true

Return type

Kirby\Cms\File

Example

if($file = $page->file('file-with-old-name.pdf')):

    try {

      $newFile = $file->rename('new-name.pdf');
      echo 'The file has been renamed';

    } catch(Exception $e) {

      echo 'The file could not be renamed';
      // optional reason: echo $e->getMessage();

    }
endif;

Source code

kirby/src/Cms/FileActions.php#L257