PHP code example of djiele / multipart

1. Go to this page and download the library: Download djiele/multipart library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

djiele / multipart example snippets



use Djiele\Http\MultipartHandler;
$mh = new MultipartHandler();
$mh->populateGlobals();
echo var_export($_POST, true), PHP_EOL;
echo var_export($_FILES, true), PHP_EOL;


|--------------------------------------------------------------------------
| 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 = 

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

XIES'] ?? $_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);


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