$file->rename($name, $safeName = true)

Renames the file and all the meta text files

  • $name (string)
    New filename
  • $safeName (boolean)
    Whether to also convert to a URL safe filename
  • return (string)
    Returns the new filename.

Example

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

try {

  $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();

}