# \[plugin cakephp-upload\] Upload\_err

**URL:** <https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686>\
**Category:** Plugins\
**Tags:** help\
**Created:** [October 17, 2022, 6:10pm UTC](https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686 "2022-10-17T18:10:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edu](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@Edu](https://discourse.cakephp.org/u/Edu)\
**Post date:** [October 17, 2022, 6:10pm UTC](https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686/1 "2022-10-17T18:10:40Z")

</div>

Hi guys, how are you?  
First, sorry for my English, I’m Brazilian and I’m learning English and CakePHP.  
So, i have an application and i need upload multiple photos.  
For this i use this plugin: [GitHub - fm-labs/cakephp-upload: CakePHP Upload Plugin](https://github.com/fm-labs/cakephp-upload#readme)  
When uploading the photo, it gives me this error:  
 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/f/f31c643246d4049a1877144b6e449b469806a839.png)

if put dd( $this-\>getRequest()-\>getData(‘uploadfile’)); i recive this message:

![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/5/582dc2f72381707f0a6490e8abebeef39f200d23.png)

so i can’t understand what’s going on

this is my controller

```auto
        if ($this->request->is('post')) {
            $uploader = new \Upload\Uploader([]);
            $uploader->upload($this->getRequest()->getData('uploadfile'));
            $result = $uploader->getResult();
        }

```

and my view:

```auto
<?= $this->Form->create(null); ?>
<?= $this->Form->input('uploadfile', ['type' => 'file']); ?>
<?= $this->Form->submit(); ?>
<?= $this->Form->end(); ?>

```

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [October 17, 2022, 6:49pm UTC](https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686/2 "2022-10-17T18:49:18Z")

</div>

Instead of using that plugin I would rather recommend you use the default CakePHP file parsing functionality which is mentioned here:  
[https://book.cakephp.org/4/en/controllers/request-response.html#file-uploads](https://book.cakephp.org/4/en/controllers/request-response.html#file-uploads)

and here

> **[Form - 4.x](https://book.cakephp.org/4/en/views/helpers/form.html#creating-file-inputs)**
>
> The FormHelper focuses on creating forms quickly, in a way that will streamline validation, re-population and layout.

Since you are uploading a file the form needs to know this as well, so you need

```auto
<?= $this->Form->create(null, ['type' => 'file']); ?>

```

instead of

```auto
<?= $this->Form->create(null); ?>

```

This will then result in a `\Laminas\Diactoros\UploadedFile` file being present inside your request data, so like

```auto
/** @var \Laminas\Diactoros\UploadedFile $file */
$file = $this->request->getData('uploadfile');

```

which then has all the necessary data inside it (see first link above)

My guess would be, that the plugin creator built this with the “old” array behavior mentioned in the first link above which can be set inside your config:

```auto
'App' => [
    // ...
    'uploadedFilesAsObjects' => false,
],

```

but I could be wrong there.

---

<div class="post-metadata">

**Author:** ![Edu](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@Edu](https://discourse.cakephp.org/u/Edu)\
**Post date:** [October 18, 2022, 2:17pm UTC](https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686/3 "2022-10-18T14:17:19Z")

</div>

> [@KevinPfeifer](#):
>
> `UploadedFile `

ok, I’m trying your way, it happens that I can save the images, however in the bank it saves only one.  
this is my controller:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/c/c9d2a5488060b45967abfbfb0fab7e62e09a06c3.png)

My view:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/b/ba6c6ef812a15665b449b87986f6d5e71d787e34.png)

My DB:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/1/197638ec6eabb0447d8c57ee9a8988717bbb43f1.png)

my local save:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/3/34d8038ade8b4c71aa17078f4f0e6c600565b749.png)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [October 18, 2022, 2:29pm UTC](https://discourse.cakephp.org/t/plugin-cakephp-upload-upload-err/10686/4 "2022-10-18T14:29:15Z")

</div>

`$photo` inside your foreach is still the same entity you created at the top with `->newEmptyEntity()`  
So it always has the same ID.

You are writing the first image name to your entity, saving it, then overwriting the name again with the second image and saving again.

If you want separate entries inside your table you need to create separate entities for each uploaded image.
