# createFile() in child page

**URL:** <https://forum.getkirby.com/t/createfile-in-child-page/33102>\
**Category:** Questions\
**Tags:** v4\
**Created:** [December 18, 2024, 7:03am UTC](https://forum.getkirby.com/t/createfile-in-child-page/33102 "2024-12-18T07:03:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![meistrwerke](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@meistrwerke](https://forum.getkirby.com/u/meistrwerke)\
**Post date:** [December 18, 2024, 7:03am UTC](https://forum.getkirby.com/t/createfile-in-child-page/33102/1 "2024-12-18T07:03:58Z")

</div>

Hello everyone,

I have created a controller with which I can create a page via the frontend on the one hand and upload and create a file on the other. Both work without any problems.

But now I want the uploaded file not to be created in the current page, but in the one I just created. At the end, a child page should be created in which a PDF file of the same name is stored.

Here is my previous code snippet, in which the file is only ever stored in the parent page, not in the child page. I am at a bit of a loss as to why this is the case.

```auto
try {

        $name = crc32($upload['name'].microtime()). '_' . $upload['name'];

        $page->createChild([
          'slug' => $name,
          'draft' => false,
          'template' => 'event',
        ]);

        $file = $page->createFile([
          'source' => $upload['tmp_name'],
          'filename' => $name,
          'template' => 'upload',
          'parent' => $page->children()->find($name),
          'content' => [
              'date' => date('Y-m-d h:m')
          ]
        ]);

        $success = 'Your file upload was successful';

      }

```

Many thanks for your help!

---

<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 18, 2024, 6:23pm UTC](https://forum.getkirby.com/t/createfile-in-child-page/33102/2 "2024-12-18T18:23:05Z")

</div>

> [@meistrwerke](#):
>
> ` $page->createFile`

$page refers to the current page, not the child.

And in any case, object in Kirby are immutable, therefore you need to store the result of an action in a new variable:

```auto
$childPage = $page->createChild([
          'slug' => $name,
          'draft' => false,
          'template' => 'event',
        ]);

```

Then

```auto
    $file = $childPage->createFile([
          'source' => $upload['tmp_name'],
          'filename' => $name,
          'template' => 'upload',
          'parent' => $page->children()->find($name),
          'content' => [
              'date' => date('Y-m-d h:m')
          ]
        ]);

```
