Skip to content

Commit

Permalink
Merge pull request #9093 from kenjis/docs-curlrequest.rst
Browse files Browse the repository at this point in the history
docs: improve CURLRequest sample code
  • Loading branch information
kenjis authored Aug 2, 2024
2 parents 82dbd91 + a2dffb3 commit fe3f489
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions user_guide_src/source/libraries/curlrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ if it's not already set:

.. literalinclude:: curlrequest/024.php

.. note:: ``form_params`` cannot be used with the ``multipart`` option. You will need to use one or the other.
.. note:: ``form_params`` cannot be used with the `multipart`_ option. You will need to use one or the other.
Use ``form_params`` for ``application/x-www-form-urlencoded`` request, and ``multipart`` for ``multipart/form-data``
requests.

Expand Down Expand Up @@ -306,13 +306,15 @@ multipart
=========

When you need to send files and other data via a POST request, you can use the ``multipart`` option, along with
the `CURLFile Class <https://www.php.net/manual/en/class.curlfile.php>`_. The values should be an associative array
of POST data to send. For safer usage, the legacy method of uploading files by prefixing their name with an `@`
the `CURLFile Class <https://www.php.net/manual/en/class.curlfile.php>`_.

The values should be an associative array
of POST data to send. For safer usage, the legacy method of uploading files by prefixing their name with an ``@``
has been disabled. Any files that you want to send must be passed as instances of CURLFile:

.. literalinclude:: curlrequest/028.php

.. note:: ``multipart`` cannot be used with the ``form_params`` option. You can only use one or the other. Use
.. note:: ``multipart`` cannot be used with the `form_params`_ option. You can only use one or the other. Use
``form_params`` for ``application/x-www-form-urlencoded`` requests, and ``multipart`` for ``multipart/form-data``
requests.

Expand Down
10 changes: 6 additions & 4 deletions user_guide_src/source/libraries/curlrequest/028.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

$post_data = [
'foo' => 'bar',
'userfile' => new \CURLFile('/path/to/file.txt'),
];
$client->request('POST', '/post', [
'multipart' => [
'foo' => 'bar',
'userfile' => new \CURLFile('/path/to/file.txt'),
],
]);

0 comments on commit fe3f489

Please sign in to comment.