0

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 server 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
Marc B
  • 356,200
  • 43
  • 426
  • 500
yesil
  • 697
  • 1
  • 9
  • 19
  • 2
    Perhaps http://www.php.net/manual/en/function.mailparse-msg-get-part.php ? – Marc B Jul 21 '11 at 15:45
  • Have a read at this previous question/answer: http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – Brian Jul 21 '11 at 16:03

2 Answers2

0

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.

Shef
  • 44,808
  • 15
  • 79
  • 90
0

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.

yesil
  • 697
  • 1
  • 9
  • 19