1 # http\Message\Body http\Message\Body::addForm([array $fields = NULL[, array $files = NULL]])
3 Add form fields and files to the message body.
5 > **Note:** Currently, http\Message\Body::addForm() creates "multipart/form-data" bodies.
10 List of form fields to add.
13 List of form files to add.
15 $fields must look like:
18 "field_name" => "value",
25 $files must look like:
29 "name" => "field_name",
30 "type" => "content/type",
31 "file" => "/path/to/file.ext"
33 "name" => "field_name2",
34 "type" => "text/plain",
38 "name" => "field_name3",
39 "type" => "image/jpeg",
41 "data" => fopen("/home/mike/Pictures/mike.jpg","r")
44 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.
48 * http\Message\Body, self.
52 * http\Exception\InvalidArgumentException
53 * http\Exception\RuntimeException
58 $body = new http\Message\Body;
60 "field_name" => "value",
67 "name" => "field_name",
68 "type" => "application/octet-stream",
69 "file" => "/run/gpm.pid"
71 "name" => "field_name2",
72 "type" => "text/plain",
73 "file" => "signature.txt",
74 "data" => "-- \nMike\n"
76 "name" => "field_name3",
77 "type" => "image/jpeg",
78 "file" => "picture.jpg",
79 "data" => fopen("/home/mike/Pictures/mike.jpg","r")
89 Content-Disposition: form-data; name="field_name"
93 Content-Disposition: form-data; name="multi_field[0]"
97 Content-Disposition: form-data; name="multi_field[1]"
101 Content-Disposition: form-data; name="field_name"; filename="gpm.pid"
102 Content-Transfer-Encoding: binary
103 Content-Type: application/octet-stream
108 Content-Disposition: form-data; name="field_name2"; filename="signature.txt"
109 Content-Transfer-Encoding: binary
110 Content-Type: text/plain
116 Content-Disposition: form-data; name="field_name3"; filename="picture.jpg"
117 Content-Transfer-Encoding: binary
118 Content-Type: image/jpeg
121 --32260b4b.3fea9114--