title: Executing Curl with PHP
body: <p>I'm trying to use <a href="http://www.docverter.com/" rel="nofollow">Docverter</a> to convert LaTeX/markdown files to PDF but am having trouble using PHP to do CURL <a href="http://www.docverter.com/api.html" rel="nofollow">to access Docverter via their API</a>. I'm know I'm not a total idiot b/c i can get this to work adapting the shell script <a href="https://github.com/Docverter/docverter/blob/master/doc/examples/html_to_pdf/convert.sh" rel="nofollow">in this Docverter example</a> and running from command line (Mac OSX).</p>
  
  <p>Using PHP's <code>exec()</code>:</p>
  
  <pre><code>$url=$_SERVER["DOCUMENT_ROOT"];
  $file='/markdown.md';
  $output= $url.'/markdown_to_pdf.pdf';
  $command="curl --form from=markdown \ 
                 --form to=pdf \ 
                 --form input_files[]=@".$url.$file." \
                 http://c.docverter.com/convert &gt; ".$output;
  exec("$command");
  </code></pre>
  
  <p>This gives no error messages but doesn't work. Is there a path issue somewhere?</p>
  
  <p><strong>UPDATE</strong> Based on @John's suggestion, here's an example using PHP's <code>curl_exec()</code> adapted from <a href="http://davidwalsh.name/curl-post" rel="nofollow">here</a>. Unfortunately this also doesn't work though at least it gives error messages.</p>
  
  <pre><code>$url = 'http://c.docverter.com/convert';
  $fields_string ='';
  $fields = array('from' =&gt; 'markdown',
          'to' =&gt; 'pdf',
          'input_files[]' =&gt; $_SERVER['DOCUMENT_ROOT'].'/markdown.md',
      );
  
      //url-ify the data for the POST
      foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
      rtrim($fields_string, '&amp;');
  
      //open connection
      $ch = curl_init();
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_URL, $url);
      curl_setopt($ch,CURLOPT_POST, count($fields));
      curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
  
      //execute post
      $result = curl_exec($ch);
  
      //close connection
      curl_close($ch);
  </code></pre>