" .
"" .
"$pro" .
"$type" .
"$format" .
"" .
$xmlRequest .= "$requestType>";
//Convert characters to proper format for HTTP POST
$xmlRequest = urlencode($xmlRequest);
// open synchronous connection to Con-way servlet and set options
$urlConn = curl_init ($requestUrl);
curl_setopt ($urlConn, CURLOPT_POST, 1);
curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, false); // May be needed for SSL behind a firewall
curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
curl_setopt ($urlConn, CURLOPT_USERPWD, $username.":".$password);
curl_setopt ($urlConn, CURLOPT_POSTFIELDS, "$requestType=$xmlRequest");
// Parse the XML Response
ob_start(); // prevent the buffer from being displayed
curl_exec($urlConn);
$xmlResponse = simplexml_load_string( ob_get_contents() );
ob_end_clean();
curl_close($urlConn); // close the connection
// Build the HTML page
echo "
Sample PHP 5 for Con-way XML $title>
Sample PHP 5 Con-way XML $title
";
// Extract your element values from the XML Response
// The outer loop iterates the total number of occurrences of your first element
for ($i=0; $i < count($xmlResponse->xpath('//'.$myElements[0])); $i++) {
// The inner loop iterates all of your elements, for each occurrence of the first
foreach ($myElements as $myEl) {
$myVals = $xmlResponse->xpath('//'.$myEl);
echo "Value of <$myEl> is: $myVals[$i] ";;
}
echo ' ';
}
// Get array of encoded image data
$imageData = $xmlResponse->xpath('//'."ImageData");
$pages = count($imageData); // number of image pages
// If image retrieval failed, display XML response with error
if ($pages==null) {
echo "Here is the dump of the XML output for $title: " .
"$xmlResponse ";
}
echo "Total image pages: $pages";
$uniqueString = date("YmdHis"); // unique number from current time
for ($i=0; $i < $pages; $i++) {
$imageDecoded = base64_decode($imageData[$i]); // decode binary image data
$pageString = ""; // page number for filename
if ($pages > 1) {
$pageString = $i+1; // if multiple pages, set page number and format
if (strlen($pageString) < 2) $pageString = "0".$pageString;
$pageString = "_".$pageString;
}
$imageLabel = "$type image for PRO number $pro - $pageString";
$fileName = $type.'-'.$pro.'-'.$uniqueString.$pageString.'.'.$format;
file_put_contents($imageDir.$fileName, $imageDecoded);
$fileUrl = $imageUrl.$fileName;
echo "";
}
echo
"" .
"";
?>