Get a record from the Adabas demo file and save the LOB to a file, the extension is determined from the mime-type stored on the file,
<?php
$id = $_GET['id'];
$reqPayloadString = <<<XML
<emp:EmployeePhotoGetElement
xmlns:emp="com.SOAGateway/EmployeePhoto">
<personnel_id>$id</personnel_id>
</emp:EmployeePhotoGetElement
> XML;
try {
$client = new WSClient(
array("to"=>"http://localhost:56000/adabas_blobs",
"useMTOM"=>TRUE,
"responseXOP"=>TRUE));
$reqMessage = new WSMessage($reqPayloadString);
$resMessage = new WSMessage('');
$resMessage = $client->request($reqMessage);
printf("Response = %s \n\n", $resMessage->str);
$cid2stringMap = $resMessage->attachments;
$cid2contentMap = $resMessage->cid2contentType;
$imageName;
if($cid2stringMap && $cid2contentMap){
foreach($cid2stringMap as $i=>$value){
$f = $cid2stringMap[$i];
$contentType = $cid2contentMap[$i];
if(strcmp($contentType,"image/pjpeg") ==0){
$imageName = "C:\\TEMP\\".$i."."."jpg";
file_put_contents($imageName, $f);
echo "<pre>File saved as
".$imageName."</pre>";
}
if(strcmp($contentType,"image/gif") ==0){
$imageName = "C:\\TEMP\\".$i."."."gif";
file_put_contents($imageName, $f);
echo "<pre>File saved as
".$imageName."</pre>";
}
if(strcmp($contentType,"audio/mpeg") ==0){
$imageName = "C:\\TEMP\\".$i."."."mp3";
file_put_contents($imageName, $f);
echo "<pre>File saved as
".$imageName."</pre>";
}
}
}else{
printf("attachments were not found ");
}
} catch (Exception $e) {
if ($e instanceof WSFault) {
printf("Soap Fault: %s\n", $e->Reason);
} else {
printf("Message = %s\n",$e->getMessage());
}
echo "<pre>";
print_r($e);
print_r($reqMessage);
print_r($resMessage);
echo "</pre>";
}