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.
53 $body = new http\Message\Body;
55 "field_name" => "value",
62 "name" => "field_name",
63 "type" => "application/octet-stream",
64 "file" => "/run/gpm.pid"
66 "name" => "field_name2",
67 "type" => "text/plain",
68 "file" => "signature.txt",
69 "data" => "-- \nMike\n"
71 "name" => "field_name3",
72 "type" => "image/jpeg",
73 "file" => "picture.jpg",
74 "data" => fopen("/home/mike/Pictures/mike.jpg","r")
84 Content-Disposition: form-data; name="field_name"
88 Content-Disposition: form-data; name="multi_field[0]"
92 Content-Disposition: form-data; name="multi_field[1]"
96 Content-Disposition: form-data; name="field_name"; filename="gpm.pid"
97 Content-Transfer-Encoding: binary
98 Content-Type: application/octet-stream
103 Content-Disposition: form-data; name="field_name2"; filename="signature.txt"
104 Content-Transfer-Encoding: binary
105 Content-Type: text/plain
111 Content-Disposition: form-data; name="field_name3"; filename="picture.jpg"
112 Content-Transfer-Encoding: binary
113 Content-Type: image/jpeg
116 --32260b4b.3fea9114--