Skip to content

File::create()

Creates a new file on disk and returns the File object. The store is used to handle file writing, so it can be replaced by any other way of generating files.

File::create(array $props): Kirby\Cms\File

Parameters

Name Type Default
$props * array

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

This method does not modify the existing $file object but returns a new object with the changes applied. Learn more →

Exceptions

Parent class

Kirby\Cms\File

Example

$file = File::create([
  'source'     => kirby()->root('assets').'/images/some-image.jpg',
  'parent'     => page('photography')->children()->listed()->first(),
  'filename'   => 'new-image.jpg',
  'template' => 'cover',
  'content'   => [
    'caption'   => 'A nice view from above',
  ]
]);