Skip to content

Kirby 3.9.8

$page->createFile()

Creates a new file

$page->createFile(array $props, bool $move = false): Kirby\Cms\File

Parameters

Name Type Default Description
$props * array
$move bool false If set to true, the source will be deleted

For the $props parameter, you pass an array with the following data, which will be used to set up the Kirby\Cms\File object:

Name Type Description
blueprint array Sets the Blueprint object
content array Sets the Content object
filename * string Sets the filename
parent * Kirby\Cms\Model Sets the parent model object
root string Always set the root to null, to invoke
auto root detection
template string
translations array Create the translations collection from an array
url string Sets the url

Return type

Kirby\Cms\File

Parent class

Kirby\Cms\Page

Example

Create new file from a local file path

$file = $page->createFile([
    'filename' => 'tree.jpg',
    'template' => 'image',
    'source'   => $kirby->root('assets'). '/images/' . 'tree.jpg',
    'parent'   => $page,
    'content'  => [
        'alt' => 'Single tree on a field'
    ],
]);