Reputation: 1055
I receive a MIME stream that contains a plain xml file and zipped xml file:
-MIMEBoundaryurn_uuid_A0162A4E6FCACE7B6C1578623716971702885
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:A0162A4E6FCACE7B6C1578623716971702886>
<?xml version='1.0' encoding='UTF-8'?><Response><Status>OK</Status><UUID>A0162A4E6FCACE7B6C1578623716971702886</UUID></Response>
--MIMEBoundaryurn_uuid_A0162A4E6FCACE7B6C1578623716971702885
Content-Type: application/zip
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:8D7801E6D98280EACC1578624071046>
PK ÇŽ)Pž¶È® Ø A0162A4E6FCACE7B6C1578623716971702886.xmlUT
....
....
--MIMEBoundaryurn_uuid_A0162A4E6FCACE7B6C1578623716971702885--
I can easily extract and parse the plain xml file directly in memory, but I've not found the way to do the same with the zipped file:
is there a way to parse the zipped xml file without saving it as a file first?
something like
$xml=simplexml_load_string ('zip://'.$zipped_xml_substring);
or
$xml=simplexml_load_string (unzip($zipped_xml_substring));
Upvotes: 4
Views: 290
Reputation: 5162
Did you checked zlib wrapper (it requires ZIP extension)?
In comments on that page you'll find few examples of usage. I will post two of them below which I think might be relevant for you:
$fp = fopen('zip://./foo.zip#bar.txt', 'r');
if( $fp ){
while( !feof($fp) ){
echo fread($fp, 8192);
}
fclose($fp);
}
or using php://input
input
file_get_contents("compress.zlib://php://input");
Upvotes: 1