Reference

Guide

$file->delete()

Deletes the file. The store is used to manipulate the filesystem or whatever you prefer.

$file->delete(): bool

Return type

bool

Example

if($file = $page->file('old-file.pdf')) {
    try {
        $file->delete();
        echo 'The file has been deleted';

    } catch(Exception $e) {
        echo 'The file could not be deleted';
        // optional reason: echo $e->getMessage();
    }
}

Source code

kirby/src/Cms/FileActions.php#L176