# Uploading Multiple Files

**URL:** <https://forum.getkirby.com/t/uploading-multiple-files/10064>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 23, 2018, 12:27am UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064 "2018-03-23T00:27:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisgwynne](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/chrisgwynne/32/5194_2.png) [@chrisgwynne](https://forum.getkirby.com/u/chrisgwynne)\
**Post date:** [March 23, 2018, 12:27am UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/1 "2018-03-23T00:27:50Z")

</div>

I’m trying to upload multiple files in one go, which is then restricted by how many I’ve set in the blueprint, if that’s possible? but it only seems to just upload one.

```auto
// Upload the images
    $count_files = 0;
if (!empty($_FILES['file']['name'])) {
  $count_files = count($_FILES['file']['name']);
}
    do {
      try {
        $upload = new Upload($p->root() . DS . '{safeFilename}', array('input' => 'file', 'index' => $index));
        $index++;
      } catch(Error $e) {
        switch($e->getCode()) {
          case Upload::ERROR_MISSING_FILE:
            // No more files have been uploaded
            $missingFile = true;
            break;
          // See the Upload class for other error values
        }
      }
    } while ($index < $count_files && !$missingFile);
    
    // Check if an image has been uploaded at all
    if($index === 0) {
      $error = 'No file uploaded.';
    }
  }

```

Not sure what I’m doing wrong.

```auto
input type="file" name="file[]" accept="image/*" multiple

```

Any assistance will be greatly appreciated.

---

<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 23, 2018, 12:39am UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/2 "2018-03-23T00:39:40Z")

</div>

Have a look at this thread here: [Problem sending images to the creation of a page (front end)](https://forum.getkirby.com/t/problem-sending-images-to-the-creation-of-a-page-front-end/9485/5)

I think what is missing in your code is the declaration of the `$missingFile` variable? It should be set to false at the beginning…

---

<div class="post-metadata">

**Author:** ![chrisgwynne](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/chrisgwynne/32/5194_2.png) [@chrisgwynne](https://forum.getkirby.com/u/chrisgwynne)\
**Post date:** [March 23, 2018, 1:05am UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/3 "2018-03-23T01:05:53Z")

</div>

Used the code in the link suggested texnixe, brilliant thank you! I assume in the array you can specify the max amount of files you can upload? I can’t find the variable for this however.

---

<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 23, 2018, 10:04am UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/4 "2018-03-23T10:04:41Z")

</div>

There is no way to limit the amount of files a user can upload via some setting in the form. You could use JavaScript to do this on the client side; additionally, you always have to check this on the server side as well.

Since `$count_files = count($_FILES['file']['name']);`gives you the number of files, you can act on this and either tell the user off (hey, you can only upload 5 files) or stop uploading after x files.

```auto
if($count_files > $max_allowed_files) {
  // go away
} else {
  // try uploading
}

```

I don’t know where you want to set this limit, but the blueprint is not the right place, because the frontend has nothing to do with blueprints (yes, I know there are plugins that allow you to read blueprint information, but that would be overkill).

---

<div class="post-metadata">

**Author:** ![chrisgwynne](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/chrisgwynne/32/5194_2.png) [@chrisgwynne](https://forum.getkirby.com/u/chrisgwynne)\
**Post date:** [March 23, 2018, 3:10pm UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/5 "2018-03-23T15:10:39Z")

</div>

Thanks texnixe, I’ll try those methods. I guess another fix would be just X amount of upload inputs.

---

<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 23, 2018, 3:11pm UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/6 "2018-03-23T15:11:52Z")

</div>

Yes, that would be an alternative.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/uploading-multiple-files/10064/7 "2025-02-06T17:28:35Z")

</div>


