title: curl to php to post a json and audio
body: <p>I'm trying to convert a curl command to be used in a php script</p>
  
  <pre><code>   curl -k -F "request={'timezone':'America/New_York','lang':'en'};type=application/json" -F "voiceData=@d8696c304d09eb1.wav;type=audio/wav" -H "Authorization: Bearer x" -H "ocp-apim-subscription-key:x" "http://example.com"
  </code></pre>
  
  <p>and here is my php script</p>
  
  <pre><code>&lt;?
  $data = array("timezone" =&gt; "America/New_York", "lang" =&gt; "en", "voiceData" =&gt; "d8696c304d09eb1.wav");                                                                    
  $data_string = json_encode($data);                                                                                   
  $ch = curl_init('https://example.com');
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-type: application/json',
     'Authorization: Bearer x',
     'ocp-apim-subscription-key:x')
  );
  $result = curl_exec($ch);
  ?&gt;
  </code></pre>
  
  <p>I understand that the send audio file bit is not right but i cant find an example how to post it.</p>
  
  <p>I have edited this in response to the post fields but if I include $ch i get no output if don't include the output complains that no post request. Any ideas?</p>
  
  <pre><code>&lt;?
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  $ch = curl_init('https://example.com');
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
     'Authorization: Bearer x',
     'ocp-apim-subscription-key:x')
  );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, 
      array('request' =&gt; json_encode(array('timezone' =&gt; 'America/New_York', 'lang' =&gt; 'en')),
            'voicedata' =&gt; new CURLFile("d8696c304d09eb1.wav")
      )
  );
  $result = curl_exec($ch);
  echo $result;
  ?&gt;
  </code></pre>