3

I need to upload files in Guzzle 6 but is mandatory to use "form_params" options. To make a POST request just with data I'm using

$client->post('http://xxx/', [
    'form_params' => [
        [
            'data' => ['id' => 1234, 'name' => 'nombre'],
            'valid' => true
        ]
    ]
]);

Since I can't use "multipart" together with "form_params", is there any way to add files inside "form_params" option in Guzzle 6? Something like this:

$client->post('http://xxx/', [
    'form_params' => [
        [
            'data' => ['id' => 1234, 'name' => 'nombre'],
            'valid' => true,
            'file1' => fopen('/path/to/file', 'r'),
            'file2_content' => 'data content'
        ]
    ]
]);

Thanks!!

Averias
  • 931
  • 1
  • 11
  • 20
  • I think you can use multipart and form_params ;) http://guzzle.readthedocs.org/en/latest/request-options.html#multipart – geggleto Dec 31 '15 at 13:48
  • If you read the below Note: "multipart cannot be used with the form_params option. You will need to use one or the other. Use form_params for application/x-www-form-urlencoded requests, and multipart for multipart/form-data requests." – Averias Dec 31 '15 at 14:15

0 Answers0