1

I am using plain php to uplaod a file. If i try testing it with postman the FILE array is empty. I know there are a lot of similar questions out there, but I they all have either a different setup, or have some simple mistakes, but I am pretty sure I checked all common errors like php.ini values and such. Here is my Php code and the postman request:

foreach ($_POST as $key => $value)
{
    echo($key . ": " . $value);
}
foreach ($_FILES as $key => $value)
{
    echo($key . ": " . $value);
}
echo(count($_FILES));

enter image description here

Here are the values of my php.ini

file_uploads = on
upload_max_filesize = 2000M
post_max_size = 2000M

Does anybody have an idea what else I could be doing wrong?

Tobias
  • 41
  • 2
  • 8
  • Are you sure you have this code `
    ` on your page...?
    – Juan Sep 23 '22 at 12:48
  • Does this answer your question? [How to send multipart/form-data request using Postman](https://stackoverflow.com/questions/16015548/how-to-send-multipart-form-data-request-using-postman) – billyonecan Sep 23 '22 at 12:50
  • To those who wrote something about the form, read the question. Regarding the content type, it is already set to "multipart/form-data; boundary=" – Tobias Sep 23 '22 at 12:56
  • @Anant-Alivetodie that actually gives me the correct output. – Tobias Sep 23 '22 at 13:08
  • I think I got it. You can't echo the content of $_FILE becuase they are not a String, so it caused an error and stopped the `echo count($_FILES)`. I think the error display is set to false which is why there was no hint whats wrong. – Tobias Sep 23 '22 at 13:11
  • I just choose the wrong way to display it. – Tobias Sep 23 '22 at 13:11

1 Answers1

1

The main issue is $_FILES here will give you single dimensional array because you are using a single file upload, so foreach ($_FILES as $key => $value) will not work.

To make it work you need to send multiple files and for that, you need to make key like barcode[]

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98