title: Upload an image to OpenFire via PHP API service
body: <p>I am building a PHP API that deals with an image upload. The image is uploaded normally to apache server using $_FILES and PHP move_uploaded_file() - this saves the file locally and is now available for a website. I also need to hit an XMPP server (OpenFire) to update an avatar using the same image, during the same process.</p>
  
  <p>I am having trouble figuring out how to approach this, I would like to grab the actual image file data from the PHP tmp/ location using the file reference found in $_FILES['userfile']['tmp_name'] - this is how we access it when we use move_uploaded_file(). Is the tmp file data still available after running move_uploaded_file()? The name would suggest not so and experiments today reveal a resource before, and false after running move_uploaded_file(). So how could I hit the image data and format it for use it in an xml packet, while still leaving the original tmp file intact for the subsequent move_uploaded_file()? - see below for xml example.</p>
  
  <p>The alternative would be to use get_file_contents() and read the file we have just saved to the filesystem - but that seems silly.</p>
  
  <p>The next bit is doing my head in. OpenFire XMPP server allows allot through the XMPP interface itself. see <a href="http://xmpp.org/extensions/xep-0084.html#examples-multiple" rel="nofollow">http://xmpp.org/extensions/xep-0084.html#examples-multiple</a> for examples of how to upload and set a users avatar.</p>
  
  <p>Someone please point me in the right direction here, I need to send an XML (XMPP) packet to the open fire server - I already have XMPPHP running and connecting to the server with no worries, its the formatting of the xml thats giving me grief.</p>
  
  <p>Example XMP packet from <a href="http://xmpp.org/extensions/xep-0084.html#examples-multiple" rel="nofollow">http://xmpp.org/extensions/xep-0084.html#examples-multiple</a> (Example 1. Publishing avatar data to data node)</p>
  
  <pre><code>&lt;iq type='set' from='juliet@capulet.lit/chamber' id='publish1'&gt;
   &lt;pubsub xmlns='http://jabber.org/protocol/pubsub'&gt;
  &lt;publish node='urn:xmpp:avatar:data'&gt;
    &lt;item id='111f4b3c50d7b0df729d299bc6f8e9ef9066971f'&gt;
      &lt;data xmlns='urn:xmpp:avatar:data'&gt;
        qANQR1DBwU4DX7jmYZnncm...
      &lt;/data&gt;
    &lt;/item&gt;
  &lt;/publish&gt;
  </code></pre>
  
  <p>
  </p>