$file->update()
Updates the file's data and ensures that media files get wiped if focus
changed
$file->update(array|null $input = null, string|null $languageCode = null, bool $validate = false): Kirby\Cms\File
Parameters
Name | Type | Default |
---|---|---|
$input | array ornull |
null
|
$languageCode | string ornull |
null
|
$validate | bool |
false
|
Return type
This method does not modify the existing $file
object but returns a new object with the changes applied. Learn more →
Exceptions
Type | Description |
---|---|
Kirby\Exception\InvalidArgumentException |
If the input array contains invalid values |
Parent class
Example
if ($file = $page->file('myimage.jpg')) {
try {
$newFile = $file->update([
'caption' => 'This is a really nice image',
'year' => 2014
]);
echo 'The meta info has been updated';
} catch(Exception $e) {
echo 'The meta info could not be updated';
// optional reason: echo $e->getMessage();
}
}
Multi-language installation
In a multi-language installation, you can pass the language of the meta data you want to update as a second argument:
if ($file = $page->file('some-file.jpg')) {
$newFile = $file->update([
'some_field' => 'new value'
], 'en');
}
if ($file = $page->file('some-file.jpg')) {
$newFile = $file->update([
'some_field' => 'new value'
], site()->language()->code());
}