# $field->toFile()

Returns a file object from a filename in the field

****

- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/methods.php#L151>

****

```php
$field->toFile(): Kirby\Cms\File|null
```

## Return types

`Kirby\Cms\File` or `null`

This method modifies the existing `$field` object it is applied to and returns it again.


## Examples

```php
<?php if ($cover = $page->cover()->toFile()): ?>
<figure class="cover">
  <img src="<?= $cover->url() ?>" alt="<?= $cover->alt() ?>">
</figure>
<?php endif ?>
```