How to send multiple files in postman ReSTful web service?

How to send multiple files in postman ReSTful web service?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to Send Multiple Files in Postman for a RESTful Web Service

When debugging a file upload endpoint, it is common to encounter a situation where your backend logic expects an array of files but receives data that looks like a single file. The specific symptom described in the source material—where $_FILES['myfile']['name'] always returns a single value and count() yields 1 regardless of how many files are attached—is almost exclusively caused by incorrect configuration in the client tool, specifically Postman.

The PHP code provided attempts to iterate through an array using $i=0; $i < $num_files. If the incoming request does not arrive as a multipart form data payload containing multiple distinct parts for the same field name, the server-side $_FILES superglobal will naturally collapse into a single entry. This is because PHP's file handling logic relies on the structure of the HTTP request body. If the client sends only one part labeled myfile, even if that part contains binary data for 5 images concatenated together, PHP treats it as one upload artifact. To make the backend array logic work, the frontend must send multiple distinct parts sharing the same field name.

In Postman, the default behavior often defaults to sending a single file when you use the "File" tab in the body section or drag-and-drop a single file into the request body. This results in the exact error seen in the screenshot from the source material. To resolve this, you must explicitly configure the form data to include multiple entries for the same key.

Navigate to the Body tab of your Postman request and ensure the mode is set to form-data. In the list of key-value pairs, you need to add a new entry for myfile for every single file you wish to upload. Do not simply append binary data to one field; instead, create distinct rows in the form data table.

KeyTypeValue
myfileFilepath/to/image1.jpg
myfileFilepath/to/image2.png
myfileFilepath/to/image3.gif

By repeating the key myfile multiple times, you instruct the HTTP client to serialize the request body with multiple Content-Disposition headers pointing to different field references. When PHP parses this multipart stream, it populates $_FILES['myfile'] as an associative array where the index corresponds to the order of appearance in the form data. This allows your code snippet:

$num_files = count($_FILES['myfile']['name']);
for( $i=0; $i < $num_files; $i++ ) {
    $name = $_FILES["myfile"]["name"][$i];
    $temp_path = $_FILES['myfile']['tmp_name'][$i];
    // ... processing logic
}

to function correctly. The count() call will now reflect the actual number of uploads, and the iteration loop can access each file's temporary path via the indexed array syntax.

It is important to note that simply concatenating binary data into a single text field or trying to send files as JSON payloads without proper multipart encoding will fail with this specific backend architecture. The backend relies on $_FILES, which is exclusively populated by multipart form data requests containing distinct file parts. If you are using a different framework that expects a flattened array or JSON representation of the files, the approach would differ entirely, but for standard PHP uploads, the duplicate field key method is the standard solution.

If you prefer not to manually add rows for every file in Postman's UI, you can use the Pre-request Script tab to dynamically generate form data based on an array of local file paths. This script can loop through a defined array and append new form data entries with the same key, ensuring the request structure matches what your PHP $_FILES handler expects before the request is even sent.

For developers looking for more robust file handling patterns in modern stacks, Laravel provides specific traits and controllers that abstract away some of these manual iteration steps, though the underlying HTTP multipart requirement remains consistent.

Our network