PHPackages                             p3k/multipart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. p3k/multipart

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

p3k/multipart
=============

Multipart Encoding Library

0.2.0(9y ago)424.8k—0%1Apache 2.0PHPPHP &gt;5.4.0

Since Jul 16Pushed 4y ago2 watchersCompare

[ Source](https://github.com/aaronpk/php-multipart-encoder)[ Packagist](https://packagist.org/packages/p3k/multipart)[ RSS](/packages/p3k-multipart/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

PHP Multipart Encoder
=====================

[](#php-multipart-encoder)

This library will build a Multipart-encoded string suitable for use in HTTP requests.

Usage
-----

[](#usage)

Requiring from `composer.json`:

```
  "p3k/multipart": "*"

```

```
// Using composer...
require('vendor/autoload.php');

// ...or requiring directly
require('src/p3k/Multipart.php');

// Create a new Multipart object
$multipart = new p3k\Multipart();

// Example POST data
$params = [
  'category' => [
    'one',
    'two'
  ],
  'name' => 'test',
  'nested' => [
    'foo' => [
      'bar1',
      'bar2'
    ],
    'bar' => 'foo'
  ]
];

// Add the params to the request
$multipart->addArray($params);

// You can add files too!
$multipart->addFile('photo', '/tmp/example.jpg', 'image/jpeg');

// Set up curl
$ch = curl_init('http://localhost:8000/server.php');
curl_setopt($ch, CURLOPT_POST, true);

// Set the POSTFIELDS to the result of this object
curl_setopt($ch, CURLOPT_POSTFIELDS, $multipart->data());

// You'll also need to set the Content-Type header
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-type: ' . $multipart->contentType()
));

curl_exec($ch);
```

Background
----------

[](#background)

The built-in cURL library does not properly encode values that are arrays when it builds a multipart request. For example, this request results in a "Notice: Array to string conversion" and the value of the parameter is "Array":

```
$params = array(
  'category' => [
    'one',
    'two'
  ]
);

$ch = curl_init('http://localhost:8000/server.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_exec($ch);
```

See PHP Bugs:

-
-

This library can be used in place of cURL's built-in encoding.

Testing
-------

[](#testing)

You can test receiving this payload with the PHP and Ruby servers provided in this project.

To run the PHP server:

```
cd servers
php -S localhost:8000

```

This will run the built-in PHP web server listening on port 8000. Run the example code above and you will see the $\_POST variable populated with the request.

To run the Ruby server, make sure you `bundle install sinatra`, then:

```
cd servers
ruby server.rb

```

Then you can post to `http://localhost:4567/upload` and you will see the JSON representation of the object that is posted.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~265 days

Total

3

Last Release

3428d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/385b302aef27e9e72ddfbf65c8b15cfce5946744fe2e541c5b415665fc2351fc?d=identicon)[aaronpk](/maintainers/aaronpk)

---

Top Contributors

[![aaronpk](https://avatars.githubusercontent.com/u/113001?v=4)](https://github.com/aaronpk "aaronpk (10 commits)")[![pwhelan](https://avatars.githubusercontent.com/u/601645?v=4)](https://github.com/pwhelan "pwhelan (2 commits)")[![voxpelli](https://avatars.githubusercontent.com/u/34457?v=4)](https://github.com/voxpelli "voxpelli (1 commits)")

### Embed Badge

![Health badge](/badges/p3k-multipart/health.svg)

```
[![Health](https://phpackages.com/badges/p3k-multipart/health.svg)](https://phpackages.com/packages/p3k-multipart)
```

###  Alternatives

[lupecode/php-trader-interface

An interface to the PHP Trader extension.

371.8k](/packages/lupecode-php-trader-interface)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
