title: Writing the following curl in PHP
body: <p>How would I write the following Curl in PHP?</p>
  
  <p>I need to automate this process in php.</p>
  
  <pre><code>$ curl -F file=@/Users/alunny/index.html -u andrew.lunny@nitobi.com -F 'data={"title":"API V1 App","package":"com.alunny.apiv1","version":"0.1.0","create_method":"file"}' https://build.phonegap.com/api/v1/apps
  </code></pre>
  
  <p>Here is the link to the Phonegap Build API.</p>
  
  <p><a href="http://docs.build.phonegap.com/en_US/developer_api_write.md.html#_post_https_build_phonegap_com_api_v1_apps" rel="nofollow">http://docs.build.phonegap.com/en_US/developer_api_write.md.html#_post_https_build_phonegap_com_api_v1_apps</a></p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>This is what I have tried so far...</p>
  
  <pre><code>&lt;?php
  
  $url = 'https://build.phonegap.com/api/v1/apps';
  $file = 'mobilecontainer.zip';
  
  $fields = array(
      'title' =&gt; 'Test App',
      'create_method' =&gt; 'file',
      'private' =&gt; 'false'
  );
  
  foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
  rtrim($fields_string, '&amp;');
  
  $ch = curl_init();
  
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch,CURLOPT_POST, count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
  curl_setopt($ch,CURLOPT_SAFE_UPLOAD, 'true');
  
  $result = curl_exec($ch);
  
  print_r($result);
  
  curl_close($ch);
  </code></pre>