title: Sending and receiving files with PHP SOAP and MTOM
body: <p>What I am trying to do is to send and receive files using MTOM with PHP and SOAP.
  There is a SOAP webservice written in JAVA that I can play without problem, except for files.</p>
  
  <p>I tried almost everything (patching Nusoap, changing the <code>__doRequest</code> in <a href="http://php.net/class.soapclient" rel="nofollow"><code>SoapClient</code></a>) without success.</p>
  
  <p>Is there any implementation of the MTOM specification in PHP?</p>
  
  <hr>
  
  <p><em>Edit:</em> Here is what I did :</p>
  
  <pre><code>public function __doRequest($request, $location, $action, $version, $one_way = 0) 
  {
      $response = parent::__doRequest($request, $location, $action, $version, $one_way);
  
      // parse $response, extract the multipart messages and so on
  
      // this part removes stuff 
      $start           = strpos($response, '&lt;?xml');
      $end             = strrpos($response, '&gt;');
      $response_string = substr($response, $start, $end - $start + 1);
      return ($response_string);
  }
  </code></pre>
  
  <p>Here is what I get : </p>
  
  <pre><code>--uuid:06cccc9f-7827-40f4-ad42-ccd60a85fba2
  Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
  Content-Transfer-Encoding: binary
  Content-ID: &lt;root.message@cxf.apache.org&gt;
  
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;soap:Body&gt;&lt;ns2:telechargerRelevesResponse xmlns:ns2="http://xxx/GestionReception/v1.0"&gt;&lt;return&gt;&lt;attachmentFile&gt;&lt;xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:98c24cf6-c72d-45f0-8b66-bf72e53670fb-168@cxf.apache.org"/&gt;&lt;/attachmentFile&gt;&lt;dateReception&gt;2013-05-30T14:04:08.000+02:00&lt;/dateReception&gt;&lt;fileName&gt;TEST-RELEVE2013053014041310846.RLV&lt;/fileName&gt;&lt;idReception&gt;36&lt;/idReception&gt;&lt;/return&gt;&lt;return&gt;&lt;attachmentFile&gt;&lt;xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:98c24cf6-c72d-45f0-8b66-bf72e53670fb-169@cxf.apache.org"/&gt;&lt;/attachmentFile&gt;&lt;dateReception&gt;2013-05-30T14:03:42.000+02:00&lt;/dateReception&gt;&lt;fileName&gt;TEST-RELEVE2013053014034873259.RLV&lt;/fileName&gt;&lt;idReception&gt;35&lt;/idReception&gt;&lt;/return&gt;&lt;/ns2:telechargerRelevesResponse&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
  --uuid:06cccc9f-7827-40f4-ad42-ccd60a85fba2
  Content-Type: text/plain
  Content-Transfer-Encoding: binary
  Content-ID: &lt;98c24cf6-c72d-45f0-8b66-bf72e53670fb-168@cxf.apache.org&gt;
  
  0111311    00001EUR2 00000000001  030113                                                  0000000384770G                0411311    00001EUR2E0000000000106060113  060113VIREMENT EMIS                    00000000 0000000005446NVIREMENT EMIS   0411311    00001EUR2E0000000000162060113  060113FRAIS SUR VIREMENT EMIS          00000000 0000000000001QFRAIS SUR VIREME0411311    00001EUR2E0000000000106060113  060113VIREMENT EMIS                    00000000
  </code></pre>