开发者

How to get by Content-Id the attachements of a multipart response with PHP CURL

I can't figure out how to get effectively a specific part of a multipart http response. I'm trying to get a PDF report from Jasper Reports serv开发者_如何学编程er by sending SOAP over PHPCURL and I didn't find in the CURL documentation how to handle multipart response. I would like to get 'report' part of the RAW response below. Thanks for any help. ilyas

------=_Part_6_9317140.1311257231623
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <B33D7700BFCF12CC2A64A7F6FB84CEAE

sutffs here
------=_Part_6_9317140.1311257231623
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <**report**>

binary PDF content here


Try this:

<?php
$str = '------=_Part_6_9317140.1311257231623
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <B33D7700BFCF12CC2A64A7F6FB84CEAE

sutffs here
------=_Part_6_9317140.1311257231623
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <**report**>

binary PDF content here';

$pattern =  '%Content-Type: application/pdf'."\n".
            'Content-Transfer-Encoding: binary'."\n".
            'Content-Id: ([^\s]+)%';

preg_match($pattern, $str, $matches);
echo $matches[1];
?>

However, I wouldn't vouch for its reliability, because the structure of the returned string might change at any time.


I modified a little Shef's solution like that:

$pattern =  "/report>\r\n\r\n/";
$matches = preg_split($pattern, $output);
file_put_contents('c:/report.pdf', $matches[1]);

And it works now. Thanks Shef.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜