Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Should work fine.</p> <pre><code>$data = array('name' =&gt; 'Ross', 'php_master' =&gt; true); // You can POST a file by prefixing with an @ (for &lt;input type="file"&gt; fields) $data['file'] = '@/home/user/world.jpg'; $handle = curl_init($url); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_exec($handle); curl_close($handle) </code></pre> <p>We have two options here, <code>CURLOPT_POST</code> which turns HTTP POST on, and <code>CURLOPT_POSTFIELDS</code> which contains an array of our post data to submit. This can be used to submit data to <code>POST</code> <code>&lt;form&gt;</code>s.</p> <hr> <p>It is important to note that <code>curl_setopt($handle, CURLOPT_POSTFIELDS, $data);</code> takes the $data in two formats, and that this determines how the post data will be encoded.</p> <ol> <li><p><code>$data</code> as an <code>array()</code>: The data will be sent as <code>multipart/form-data</code> which is not always accepted by the server.</p> <pre><code>$data = array('name' =&gt; 'Ross', 'php_master' =&gt; true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); </code></pre></li> <li><p><code>$data</code> as url encoded string: The data will be sent as <code>application/x-www-form-urlencoded</code>, which is the default encoding for submitted html form data.</p> <pre><code>$data = array('name' =&gt; 'Ross', 'php_master' =&gt; true); curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data)); </code></pre></li> </ol> <p>I hope this will help others save their time.</p> <p>See: </p> <ul> <li><a href="http://www.php.net/manual/en/function.curl-init.php" rel="noreferrer"><code>curl_init</code></a></li> <li><a href="http://www.php.net/manual/en/function.curl-setopt.php" rel="noreferrer"><code>curl_setopt</code></a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload