PHPackages                             djiele/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. [HTTP &amp; Networking](/categories/http)
4. /
5. djiele/multipart

ActiveLibrary[HTTP &amp; Networking](/categories/http)

djiele/multipart
================

Parse HTTP multipart/form-data request body. Useful for REST APIs.

7.3.1-stable(5y ago)2774MITPHP

Since Aug 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/djiele/multipart-handler)[ Packagist](https://packagist.org/packages/djiele/multipart)[ RSS](/packages/djiele-multipart/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (0)

multipart-handler
=================

[](#multipart-handler)

- This class became necessary during the development of a REST API and had no access to server config and install the "apfd" extension ([Linux module](https://pecl.php.net/package/apfd)) ([Windows](https://www.djiele.net/pecl-db/?search%5BextName%5D=apfd)) . This class parses HTTP multipart/form-data request bodies and try to populate `$_FILES` and `$_POST` as PHP would do. The idea was to be able to handle very big files with no memory overflow. The `php://input` stream is read in chunks of 8192 bytes that are written directly to disk, so very small memory footprint.

At this time there is no check on '`post_max_size`', '`upload_max_filesize`', '`max_file_uploads`' and '`max_input_vars`'. Maybe in a future release this checks will be done to be compliant with server configuration.

##### Installation

[](#installation)

You can install the package via composer:

```
composer require djiele/multipart dev-master

```

##### Simple usage

[](#simple-usage)

```
require_once __DIR__'./vendor/autoload.php';
use Djiele\Http\MultipartHandler;
$mh = new MultipartHandler();
$mh->populateGlobals();
echo var_export($_POST, true), PHP_EOL;
echo var_export($_FILES, true), PHP_EOL;
```

##### Using the package with frameworks

[](#using-the-package-with-frameworks)

just instanciate the class at the very beginning of the framework boot. You have to make sure that the class object will be destroyed at the very end of script or application. Otherwise the uploaded files will be deleted by the destructor before your script can process them. For frameworks like Laravel or Symfony i usually instanciate the handler as a public member of 'app' and 'kernel' respectively.

Sample code for Laravel

in public/index.php, just after the app is created you can add this little code:

```
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

### multipartHandler call if request is PUT, PATCH, OR DELETE
if (
	isset($_SERVER['REQUEST_METHOD'])
	&& in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH', 'DELETE'])
) {
    $app->multipartHandler = new Djiele\Http\MultipartHandler();
    $app->multipartHandler->populateGlobals();
}
###
```

At this step the `$_POST` and `$_FILES` super globals are a populated as would PHP with regular POST method. The framework can then populate the Request-&gt;files collection and gives you the ability to use UploadedFile objects as you would do normally. Note that you can not use the 'move' method since it make use of the 'move\_uploaded\_file' native function of PHP which checks that files where uploaded during POST request. You can to use UploadedFile::store() or UploadedFile::storeAs() and then delete the temporary file.

```

$request->file('id')->storeAs('somedir', $uploadedFile->getClientOriginalName());
unlink($uploadedFile->getPathName());

```

Sample code for symfony

in the file public/index.php just after the kernel is created add the same little code:

```
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
use Djiele\Http\MultipartHandler;

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);

### multipartHandler call if request is PUT, PATCH, OR DELETE
if (
    isset($_SERVER['REQUEST_METHOD'])
    && in_array($_SERVER['REQUEST_METHOD'], ['PUT', 'PATCH', 'DELETE'])
) {
    $kernel->multipartHandler = new MultipartHandler();
    $kernel->multipartHandler->populateGlobals();
}
###

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
```

Same remarks and notices as Laravel

Et voilà!

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

2109d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40306999?v=4)[djiele](/maintainers/djiele)[@djiele](https://github.com/djiele)

---

Top Contributors

[![djiele](https://avatars.githubusercontent.com/u/40306999?v=4)](https://github.com/djiele "djiele (25 commits)")

---

Tags

httpsymfonylaravelrestmultipartform-data

### Embed Badge

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

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

###  Alternatives

[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

400509.0k3](/packages/pusher-pusher-http-laravel)[srio/rest-upload-bundle

Handle multiple rest upload ways

46124.8k](/packages/srio-rest-upload-bundle)[apoca/laravel-sibs-payments

Laravel library to communicate with SIBS - Open Payment Platform.

342.3k](/packages/apoca-laravel-sibs-payments)[sockeon/sockeon

Framework-agnostic PHP WebSocket and HTTP server library with attribute-based routing and support for namespaces and rooms.

291.3k2](/packages/sockeon-sockeon)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

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