1 # http\Message\Body http\Message\Body::addForm([array $fields = NULL[, array $files = NULL]])
3 Add form fields and files to the message body.
6 > Currently, http\Message\Body::addForm() creates "multipart/form-data" bodies.
10 * array $fields = NULL
11 List of form fields to add.
14 List of form files to add.
16 $fields must look like:
19 "field_name" => "value",
26 $files must look like:
30 "name" => "field_name",
31 "type" => "content/type",
32 "file" => "/path/to/file.ext"
34 "name" => "field_name2",
35 "type" => "text/plain",
39 "name" => "field_name3",
40 "type" => "image/jpeg",
42 "data" => fopen("/home/mike/Pictures/mike.jpg","r")
45 As you can see, a file structure must contain a "file" entry, which holds a file path, and an optional "data" entry, which may either contain a resource to read from or the actual data as string.
49 * http\Message\Body, self.
53 * http\Exception\InvalidArgumentException
54 * http\Exception\RuntimeException
59 $body = new http\Message\Body;
61 "field_name" => "value",
68 "name" => "field_name",
69 "type" => "application/octet-stream",
70 "file" => "/run/gpm.pid"
72 "name" => "field_name2",
73 "type" => "text/plain",
74 "file" => "signature.txt",
75 "data" => "-- \nMike\n"
77 "name" => "field_name3",
78 "type" => "image/jpeg",
79 "file" => "picture.jpg",
80 "data" => fopen("/home/mike/Pictures/mike.jpg","r")
90 Content-Disposition: form-data; name="field_name"
94 Content-Disposition: form-data; name="multi_field[0]"
98 Content-Disposition: form-data; name="multi_field[1]"
102 Content-Disposition: form-data; name="field_name"; filename="gpm.pid"
103 Content-Transfer-Encoding: binary
104 Content-Type: application/octet-stream
109 Content-Disposition: form-data; name="field_name2"; filename="signature.txt"
110 Content-Transfer-Encoding: binary
111 Content-Type: text/plain
117 Content-Disposition: form-data; name="field_name3"; filename="picture.jpg"
118 Content-Transfer-Encoding: binary
119 Content-Type: image/jpeg
122 --32260b4b.3fea9114--