Documentation

Multipart
in package

HTTP multipart/form-data builder and parser (RFC 7578)

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Methods

build()  : Body
Build a rendered multipart/form-data body (RFC 7578) from a request data array.
generateBoundary()  : string
Generate a random multipart boundary
parse()  : array<string|int, mixed>
Parse a raw multipart/form-data body into a flat data array
toArray()  : array<string|int, mixed>
Convert a request data array into a curl-native array (scalars + CURLFile), suitable for CURLOPT_POSTFIELDS. Curl streams CURLFile entries directly from disk and builds the multipart framing itself - no buffering here.
escapeHeaderValue()  : string
Escape a value for safe use inside a quoted Content-Disposition/Content-Type parameter
toCurlFile()  : CURLFile
Convert a single file-field value (by path, or by raw contents) into a CURLFile
writeFilePart()  : void
Write one file part to the output stream, streaming the file's content directly rather than reading it into a string first
writeScalarPart()  : void
Write one non-file part to the output stream

Methods

build()

Build a rendered multipart/form-data body (RFC 7578) from a request data array.

public static build(array<string|int, mixed> $data[, string|null $boundary = null ]) : Body

File fields are streamed from disk into the output, not buffered as strings.

Parameters
$data : array<string|int, mixed>
$boundary : string|null = null
Return values
Body

generateBoundary()

Generate a random multipart boundary

public static generateBoundary() : string
Return values
string

parse()

Parse a raw multipart/form-data body into a flat data array

public static parse(string $rawBody, string $boundary) : array<string|int, mixed>
Parameters
$rawBody : string
$boundary : string
Return values
array<string|int, mixed>

toArray()

Convert a request data array into a curl-native array (scalars + CURLFile), suitable for CURLOPT_POSTFIELDS. Curl streams CURLFile entries directly from disk and builds the multipart framing itself - no buffering here.

public static toArray(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
Return values
array<string|int, mixed>

escapeHeaderValue()

Escape a value for safe use inside a quoted Content-Disposition/Content-Type parameter

protected static escapeHeaderValue(string $value) : string
Parameters
$value : string
Return values
string

toCurlFile()

Convert a single file-field value (by path, or by raw contents) into a CURLFile

protected static toCurlFile(array<string|int, mixed> $value) : CURLFile
Parameters
$value : array<string|int, mixed>
Return values
CURLFile

writeFilePart()

Write one file part to the output stream, streaming the file's content directly rather than reading it into a string first

protected static writeFilePart(resource $output, string $boundary, string $name, array<string|int, mixed> $value) : void
Parameters
$output : resource
$boundary : string
$name : string
$value : array<string|int, mixed>
Tags
throws
Exception

writeScalarPart()

Write one non-file part to the output stream

protected static writeScalarPart(resource $output, string $boundary, string $name, string $value) : void
Parameters
$output : resource
$boundary : string
$name : string
$value : string

        
On this page

Search results