title: PHP upload file from server to another server using curl post
body: <p>I need some help please.</p>
  
  <p>I have a php script which generates a xml file and then i need to submit this to another server using POST. The XML file is ok as i can manually upload it using curl from the command line.</p>
  
  <p>my code is:</p>
  
  <pre><code>$file = 'temp.xml';
  file_put_contents($file, $output);
  $post = array('extra_info' =&gt; '123456','file_contents'=&gt;'@'.$file);
  $url = "&lt;URL&gt;";
  $chlead = curl_init();
  curl_setopt($chlead, CURLOPT_USERPWD, "&lt;USER&gt;:&lt;PASSWORD&gt;");
  curl_setopt($chlead, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($chlead, CURLOPT_URL, $url);
  curl_setopt($chlead, CURLOPT_VERBOSE, 1);
  curl_setopt($chlead, CURLOPT_POST,1);
  curl_setopt($chlead, CURLOPT_POSTFIELDS, $post);
  curl_setopt($chlead, CURLOPT_RETURNTRANSFER, false);
  $response = curl_exec($chlead);
  </code></pre>
  
  <p>I can manually upload the file to the server which handles is correctly by:</p>
  
  <pre><code>curl -v -k -u &lt;USER&gt;:&lt;PASSWORD&gt; -X POST --upload-file temp.xml &lt;URL&gt;
  </code></pre>
  
  <p>What am i missing? I am using PHP 5.2.17. Also if there is a way of doing this without writing the xml file to disk that would be good to know.</p>
  
  <p>Thanks</p>