title: post binary from variable along with plain text using curl with php
body: <p>I know of posting only binary:</p>
  
  <pre><code>$file_contents = file_get_contents("http://example.org/image.jpg");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $file_contents); 
  </code></pre>
  
  <p>as well as posting text along with binary from a file on disk:</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    "name" =&gt; "peter",
    "msg" =&gt; "hello",
    "foo" =&gt; "@file/on/disk/image.jpg"
  ));
  </code></pre>
  
  <p>But what I can't figure out is how to post binary data directly from a variable (e.g. $file_contents) along with plain text key-value pairs. Is this possible with curl?</p>
  
  <p>The reason I'm asking is that I'm using the facebook API to create events and need to upload an image along the rest of the event data. Because I'm getting the images from the internet it would be great if I didn't have to save them on disk before posting, then delete them from disk, but instead do the post directly with the data from file_get_contents() saved in a php variable.</p>