# Why does file.\*:after hook not fire?

**URL:** <https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 28, 2022, 8:30am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400 "2022-12-28T08:30:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonigo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sonigo/32/12610_2.png) [@sonigo](https://forum.getkirby.com/u/sonigo)\
**Post date:** [December 28, 2022, 8:30am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/1 "2022-12-28T08:30:41Z")

</div>

Hi there

I’m trying to create a hook after a file has been uploaded/replaced in the files field.  
But none of the file hooks fire. Am I misunderstanding how the file hooks work?  
Because the page.update:after hook is working for me.

blueprint

```auto
fields:
  type: fields
  fields:
    excel:
      type: files
      multiple: false

```

in config.php

```auto
    'hooks' => [
        'file.create:after' => function (Kirby\Cms\File $file) {
            throw new Exception('file.create:after');
        },
        'file.update:after' => function (Kirby\Cms\File $newFile, Kirby\Cms\File $oldFile) {
            throw new Exception('file.update:after');
        },
        'file.replace:after' => function (Kirby\Cms\File $file, Kirby\Filesystem\File $upload) {
            throw new Exception('file.replace:after');
        },
        'page.update:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {
            throw new Exception('page.update:after');
        }
    ],

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 28, 2022, 9:07am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/2 "2022-12-28T09:07:23Z")

</div>

All hooks apart from the file.replace:after look good and should work, the replace hook should have $oldFile and $newFile as params, not $file/$upload.

---

<div class="post-metadata">

**Author:** ![sonigo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sonigo/32/12610_2.png) [@sonigo](https://forum.getkirby.com/u/sonigo)\
**Post date:** [December 28, 2022, 9:21am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/3 "2022-12-28T09:21:05Z")

</div>

Thanks for the reply!

Even after fixing the parameters, the file hooks don’t trigger (or in my case don’t throw an exception) if I replace/upload a file to the files field on the page.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 28, 2022, 9:23am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/4 "2022-12-28T09:23:54Z")

</div>

Hm, you cannot replace a file via the files field, but the hook should at least be triggered on upload.

---

<div class="post-metadata">

**Author:** ![sonigo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sonigo/32/12610_2.png) [@sonigo](https://forum.getkirby.com/u/sonigo)\
**Post date:** [December 28, 2022, 9:29am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/5 "2022-12-28T09:29:09Z")

</div>

You were right! I added the ‘file.create:after’ hook which then triggered when I uploaded the file!  
So if I understand it correctly, the file hooks trigger when you actually interacting with the filesystem and not with the panel?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 28, 2022, 9:44am UTC](https://forum.getkirby.com/t/why-does-file-after-hook-not-fire/27400/6 "2022-12-28T09:44:40Z")

</div>

Well, the hooks trigger depending on the actions. file.replace actually means that you replace an already uploaded file with another file (see `replace` option in the file view). The file.replace hook doesn’t trigger if you select file a instead of file b in a files field.
