title: POSTing a multipart/form-data without user intervention in PHP
body: <p>I need to POST some XML data to a remote server for processing.  The server protocol is already defined and unchangeable.  The XML data I want to post is dynamically generated within a PHP page running on a local server.  I do not want the user to have to save that XML data to a file and then browse for the file to upload it to the remote server (this would not be user-friendly and pointless).  My question is how to do this using PHP functions (it would be possible to do it by coding an HTML form with an 'input file=' field, but this means that the user has to browse for the file).  I have been given an example, and  what I need is to write PHP code that will <strong>exactly</strong> reproduce the headers in the example and send it to the remote server.  Any clues to help me?</p>
  
  <pre><code>POST http://doi.crossref.org/servlet/deposit?  operation=doMDUpload&amp;login_id=USER&amp;login_passwd=PSWD&amp;area=live HTTP/1.1 
  Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* 
  Accept-Language: en-us Content-Type: multipart/form-data; boundary=---------------------------7d22911b10028e 
  User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461) 
  Host: Myhost 
  Content-length: 1304 Pragma: no-cache -----------------------------7d22911b10028e 
  Content-Disposition: form-data; name="fname"; filename="crossref_query.xml" 
  &lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  
  .....XML data....
  
  -----------------------------7d22911b10028e--
  </code></pre>
  
  <p>Things I have tried without success: a form and a input=hidden field for the XML data (the POSTed data does not include a filename and so is rejected by the remote server); http_post_data() - just gave me an internal server error at the remote server; hand coding the data stream and sending it through a a port 80 socket after using fopensocket - the server didn't recognise that the stream contained POSTed form data, even after checking the stream I sent, character by character using tcpdump.  So as you can tell, I'm getting desperate!</p>