# Single file upload from frontend instead of array

**URL:** <https://forum.getkirby.com/t/single-file-upload-from-frontend-instead-of-array/27436>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 2, 2023, 3:44pm UTC](https://forum.getkirby.com/t/single-file-upload-from-frontend-instead-of-array/27436 "2023-01-02T15:44:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Studio.dier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/studio.dier/32/11289_2.png) [@Studio.dier](https://forum.getkirby.com/u/Studio.dier)\
**Post date:** [January 2, 2023, 3:44pm UTC](https://forum.getkirby.com/t/single-file-upload-from-frontend-instead-of-array/27436/1 "2023-01-02T15:44:05Z")

</div>

Hello there! Happy new year 🙂

I’ve tried refactoring this:

> **[Uploading files](https://getkirby.com/docs/cookbook/forms/file-uploads)**
>
> Learn how to upload files through a frontend form.

To work for a single file upload. In the frontend I make use of vue, but it’s mainly a regular html-form with a post request that redirects to the page with the controller. The controller creates a page (this part works) & uploads a cover file (this part doesn’t work).

the vue form:

```auto
// 'site.drawlink' links to page with the controller

    <form id="form" :action="site.drawlink" method="POST">
      <input name="file" type="file" required />
      <label for="submitter">Who's submitting?</label>
      <input name="submitter" type="text" placeholder="full name*" required />
      <input name="email" type="email" placeholder="e-mail*" required />
      <input name="date" type="text" :value="fulldate" required hidden />
      <input type="submit" name="register" value="SUBMIT!" />
    </form>

```

The controller:

```auto
<?php
return function ($kirby, $page) {

    if ($kirby->request()->is('POST') === true && get('register')) {

        $data = [
            'submitter' => get('submitter'),
            'email' => get('email'),
            'date' => get('date'),
        ];

        if ($invalid = invalid($data)) {
            $alert = $invalid;
        } else {

            $upload = $kirby->request()->file()->get('file');
            $kirby->impersonate('kirby');

            try {
                $registration = $page->createChild([
                    'slug' => $data['submitter'] . " " . $data['date'],
                    'template' => 'drawing',
                    'num' => $page->children()->listed()->count() + 1,
                    'content' => $data,
                ]);                
                try {
                    $name = "cover";
                    $registration->createFile([
                        'source' => $upload['tmp_name'],
                        'filename' => $name,
                        'template' => 'cover',
                        'content' => [
                            'date' => date('Y-m-d h:m')
                        ]
                    ]);
                } catch (Exception $e) {
                    $alerts[$upload['name']] = $e->getMessage();
                }
                if ($registration) {
                    $registration->changeStatus('unlisted');
                    go('drawings');
                }
            }            
            
            catch (Exception $e) {
                $alert = ['Your registration failed: ' . $e->getMessage()];
                go('error');
            }
        }
    }

    // return data to template
    return [
        'alert' => $alert ?? null,
        'data' => $data ?? false,
    ];
};

```

When I submit a completed form I get to the debug page with the message ‘Kirby\Http\Request::file(), 0 passed’

Something I’m misunderstanding?

---

<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:** [January 2, 2023, 3:50pm UTC](https://forum.getkirby.com/t/single-file-upload-from-frontend-instead-of-array/27436/2 "2023-01-02T15:50:14Z")

</div>

> [@Studio.dier](#):
>
> ` $upload = $kirby->request()->file()->get('file');`

If you use `file()` instead of `files()`, you need to pass a key as parameter, see the documentation.  
[File:](https://getkirby.com/docs/reference/objects/http/request/file)

And then you cannot call `get()` on it.

---

<div class="post-metadata">

**Author:** ![Studio.dier](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/studio.dier/32/11289_2.png) [@Studio.dier](https://forum.getkirby.com/u/Studio.dier)\
**Post date:** [January 3, 2023, 1:39pm UTC](https://forum.getkirby.com/t/single-file-upload-from-frontend-instead-of-array/27436/3 "2023-01-03T13:39:05Z")

</div>

I made it work with the files instead of file 🙂 thanks for the quick reply again!

I do have have a follow-up question, but this could be another post on the forum to keep it separated.
