2017 © Pedro Peláez
 

library multipart-parser

One class library to parse multipart content with encoding and charset support.

image

riverline/multipart-parser

One class library to parse multipart content with encoding and charset support.

  • Wednesday, April 18, 2018
  • by rcambien
  • Repository
  • 5 Watchers
  • 14 Stars
  • 52,210 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 16 Versions
  • 19 % Grown

The README.md

README

PHP, (*1)

What is Riverline\MultiPartParser

Riverline\MultiPartParse is a one class library to parse multipart documents (multipart email, multipart form, etc ...) and manage each part encoding and charset to extract their content., (*2)

Requirements

  • PHP >= 5.6

Installation

Riverline\MultiPartParse is compatible with composer and any psr-0/psr-4 autoloader., (*3)

composer require riverline/multipart-parser

Usage

<?php

use Riverline\MultiPartParser\StreamedPart;

// Prepare a test stream
$data = <<<EOL
User-Agent: curl/7.21.2 (x86_64-apple-darwin)
Host: localhost:8080
Accept: */*
Content-Type: multipart/form-data; boundary=----------------------------83ff53821b7c

------------------------------83ff53821b7c
Content-Disposition: form-data; name="foo"

bar
------------------------------83ff53821b7c
Content-Transfer-Encoding: base64

YmFzZTY0
------------------------------83ff53821b7c
Content-Disposition: form-data; name="upload"; filename="text.txt"
Content-Type: text/plain

File content
------------------------------83ff53821b7c--
EOL;
$stream = fopen('php://temp', 'rw');
fwrite($stream, $data);
rewind($stream);

$document = new StreamedPart($stream);

if ($document->isMultiPart()) {
    $parts = $document->getParts();
    echo $parts[0]->getBody(); // Output bar
    // It decode encoded content
    echo $parts[1]->getBody(); // Output base64

    // You can also filter by part name
    $parts = $document->getPartsByName('foo');
    echo $parts[0]->getName(); // Output foo

    // You can extract the headers
    $contentDisposition = $parts[0]->getHeader('Content-Disposition');
    echo $contentDisposition; // Output Content-Disposition: form-data; name="foo"
    // Helpers
    echo StreamedPart::getHeaderValue($contentDisposition); // Output form-data
    echo StreamedPart::getHeaderOption($contentDisposition, 'name'); // Output foo

    // File helper
    if ($parts[2]->isFile()) {
        echo $parts[2]->getFileName(); // Output text.txt
        echo $parts[2]->getMimeType(); // Output text/plain
    }
}

Converters

The library also provides three converters to quickly parse PSR-7, HttpFoundation and native requests., (*4)

<?php

use \Riverline\MultiPartParser\Converters;

// Parse $_SERVER and STDIN
$document = Converters\Globals::convert();

Backward compatibility

The old Part parser is now deprecated and replaced with a wrapper class that create a temporary stream from the string content and call the new StreamedPart parser., (*5)

The Versions

18/04 2018

dev-master

9999999-dev

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Romain Cambien

parser http multipart

18/04 2018

1.2.0

1.2.0.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Romain Cambien

parser http multipart

18/04 2018

dev-rfc5987

dev-rfc5987

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Romain Cambien

parser http multipart

18/04 2018

1.1.10

1.1.10.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Romain Cambien

parser http multipart

16/01 2018

1.1.9

1.1.9.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Romain Cambien

parser http multipart

17/12 2015

1.1.8

1.1.8.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

17/12 2015

1.1.7

1.1.7.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

07/12 2015

1.1.6

1.1.6.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

04/12 2015

1.1.5

1.1.5.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

10/11 2015

1.1.4

1.1.4.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

09/11 2015

1.1.3

1.1.3.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

09/11 2015

1.1.2

1.1.2.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

06/11 2015

1.1.1

1.1.1.0

One class library to parse multipart content with encoding and charset support.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

05/11 2015

1.1.0

1.1.0.0

Library to parse multipart requests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain Cambien

parser http multipart

05/11 2015

1.0.0

1.0.0.0

Library to parse multipart requests

  Sources   Download

MIT

The Requires

  • php >=5.1

 

by Romain Cambien

parser http multipart

05/11 2015

0.0.1

0.0.1.0

Library to parse multipart requests

  Sources   Download

MIT

The Requires

  • php >=5.1

 

by Romain Cambien

parser http multipart