# Uniform file sending problem

**URL:** <https://forum.getkirby.com/t/uniform-file-sending-problem/17355>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 20, 2020, 6:23pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355 "2020-02-20T18:23:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 20, 2020, 6:23pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/1 "2020-02-20T18:23:33Z")

</div>

When I try to send a form with some files using Uniform, I always get an error message that the file format is not correct, even if the file format is right.

This is the controller code:

```
<?php

use Uniform\Form;

return function ($kirby) {
   $form = new Form([
      'bewerbungals' => [
	      'rules' => ['required'],
         'message' => 'Geben Sie die Stelle ein, für die Sie sich bewerben',
      ],
      'name' => [
	      'rules' => ['required'],
         'message' => 'Geben Sie Ihren Namen ein',
      ],
      'strasse' => [
	      'rules' => ['required'],
         'message' => 'Geben Sie Ihre Strasse und Hausnummer ein',
      ],
      'plzort' => [
	      'rules' => ['required'],
         'message' => 'Geben Sie Ihren Wohnort und Ihre Postleitzahl ein',
      ],
      'telefon' => [
	      'rules' => ['required'],
         'message' => 'Geben Sie Ihre Telefonnummer ein',
      ],
      'fax' => [],
      
      'email' => [
         'rules' => ['required', 'email'],
         'message' => 'Geben Sie Ihre Emailadresse ein',
      ],
      
      'filefield1' => [
            'rules' => [
                'required',
                'file',
                'mime' => ['application/pdf'],
                'filesize' => 3000,
            ],
            'message' => [
                'Please choose a file.',
	            'Bitte senden Sie ausschliesslich Dateien.',
                'Bitte senden Sie ausschliesslich PDF, Word und Jpeg-Dateien.',
                'Die gesendeten Dateien müssen kleiner als 3MB sein.',
            ],
        ],
      
      'filefield2' => [
            'rules' => [
                'required',
                'file',
                'mime' => ['application/pdf'],
                'filesize' => 3000,
            ],
            'message' => [
                'Please choose a file.',
	            'Bitte senden Sie ausschliesslich Dateien.',
                'Bitte senden Sie ausschliesslich PDF, Word und Jpeg-Dateien.',
                'Die gesendeten Dateien müssen kleiner als 3MB sein.',
            ],
        ],
      
      'filefield3' => [
            'rules' => [
                'required',
                'file',
                'mime' => ['application/pdf'],
                'filesize' => 3000,
            ],
            'message' => [
                'Please choose a file.',
	            'Bitte senden Sie ausschliesslich Dateien.',
                'Bitte senden Sie ausschliesslich PDF, Word und Jpeg-Dateien.',
                'Die gesendeten Dateien müssen kleiner als 3MB sein.',
            ],
        ],
      
      'datenschutz' => [
          'rules' => ['required'],
          'message' => 'Markieren Sie die Checkbox für die Datenschutzerklärung',
      ],
        
   ]);
   
  
 // get the uploads
        $upload1 = $kirby->request()->files()->get('filefield1');
        $upload2 = $kirby->request()->files()->get('filefield2');
        $upload3 = $kirby->request()->files()->get('filefield3');
	
        $uploads = array($upload1, $upload2, $upload3);
	
	
  // loop through uploads and check if they are valid
        

   if ($kirby->request()->is('POST')) {
	  foreach ($uploads as $upload) {

		// if no file is uploaded (its not required)
            if ($upload['error'] === 4) {

                	// do nothing
          
            } else {

           
                $name = $upload['tmp_name'];
                $tmpName = pathinfo($name);
                // sanitize the original filename
                $filename = $tmpName['dirname']. '/'. F::safeName($upload['name']);

                if (rename($upload['tmp_name'], $filename)) {
                    $name = $filename;
                }
                // add the files to the attachments array
                $attachments[] = $name;
            }  
        }; 
	  
	   
      $form->emailAction([
	     'template' => 'email',
         'to' => 'guy@t-online.de',
         'from' => 'bewerbung@job.de',
         'subject' => 'Neue Bewerbung von {{email}}',
         'attachments' => $attachments,
      ]);   
   };

   return compact('form');
};

```

Strangely enough, if I send the form without a file, I get the second error message (‘Bitte senden Sie ausschliesslich Dateien.’). Shouldn’t that be the first one in this case (for ‘required’)?

What could be the reason for this?

---

<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:** [February 20, 2020, 6:47pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/2 "2020-02-20T18:47:25Z")

</div>

What do you get if you send files and then dump `$uploads`?

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 20, 2020, 6:49pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/3 "2020-02-20T18:49:57Z")

</div>

An empty Array:

```
Array
(
    [0] => 
    [1] => 
    [2] => 
)

```

If i remove the rules ‘required’ and ‘file’ the form is send as an email with all the files, but the file recognition with mime is not accounted for, you can send any filetype.

---

<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:** [February 20, 2020, 10:41pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/4 "2020-02-20T22:41:26Z")

</div>

Hm, could you send me the (reduced) project via a download link for testing?

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 22, 2020, 2:55pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/5 "2020-02-22T14:55:41Z")

</div>

I would be grateful to do so, thank you very much.

Can I send the link to the email address in your website?

---

<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:** [February 22, 2020, 2:56pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/6 "2020-02-22T14:56:34Z")

</div>

Yes, you can do either that or send me a PM here.

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 22, 2020, 3:29pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/7 "2020-02-22T15:29:12Z")

</div>

I have sent the link to the email address.

---

<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:** [February 22, 2020, 3:56pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/8 "2020-02-22T15:56:06Z")

</div>

Got it!

---

<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:** [February 22, 2020, 7:35pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/9 "2020-02-22T19:35:09Z")

</div>

Hm, I don’t know what the problem is here, if I use the upload action instead of the email action, file validation works as expected.

I have never sent attachments with Uniform, only using the Kirby way as in this recipe: [https://getkirby.com/docs/cookbook/forms/email-with-attachments](https://getkirby.com/docs/cookbook/forms/email-with-attachments)

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 26, 2020, 3:03pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/10 "2020-02-26T15:03:51Z")

</div>

If I use the upload action instead of the email action, the validation still does not work. PDFs are not recognized. Did you change anything else?

---

<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:** [February 26, 2020, 3:07pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/11 "2020-02-26T15:07:17Z")

</div>

> [@Gert](#):
>
> Did you change anything else?

Well, I simplified the whole form to have only a single form field and two upload fields because I hate testing with lots of unnecessary stuff… But apart from that, not really.

---

<div class="post-metadata">

**Author:** ![Gert](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@Gert](https://forum.getkirby.com/u/Gert)\
**Post date:** [February 29, 2020, 3:47pm UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/12 "2020-02-29T15:47:50Z")

</div>

Thanks for your help. I’m going to use the “email with attachments” method instead.  
I honestly don’t see why you would need to upload the form content with attachments to Kirby. It’s IMHO much more convenient to have everything in one email.

---

<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:** [March 1, 2020, 12:27am UTC](https://forum.getkirby.com/t/uniform-file-sending-problem/17355/13 "2020-03-01T00:27:31Z")

</div>

> [@Gert](#):
>
> I honestly don’t see why you would need to upload the form content with attachments to Kirby.

No, that is in fact not necessary.
