2.1
PrintShop Web Print Production Integration | 13
Sample POST receive script
The following script is a sample on how to receive POST data in PHP. The code receives the XML
data sent by the XML to File connector and writes this information to disk using the ID of the order. The
sample file is supplied with PSW 2.1 and can be found at the following location:
C:\Program Files\PrintShop Web\Website\modules\printproduction\2\sample\receive.php
<?
/**
* Sample POST receive page
*
* This demo script creates a xml file based on the JobID of the received XML.
* The file is saved directly under the "C" directory
*
* To use this script, the following must be applied
* The module "XML to File" must be activated on "Settings"
* Either "Post" or "Move to folder and Post" must be selected as "PushMethod"
* "http://localhost/modules/printproduction/2/sample/receive.php" must be entered in
"URL"
* Finally, as you change the status of the order, then "JobID.xml" will be created in
"C" directory
*
*/
$aParams[cContent] = $_POST[PSW_XML];
$aJobXML = simplexml_load_string($aParams[cContent] );
$aOrderID = $aJobXML->xpath('//fnOrderID');
$cDirectory = "C:/".$aOrderID[0].".xml";
if (!$handle = @fopen($cDirectory, 'w')) {
echo "Cannot open Ticket file ($cDirectory)";
exit;
}
if (fwrite($handle, $aParams[cContent]) === FALSE) {
echo "Cannot write to file ($cDirectory)";
exit;
}
fclose($handle);
chmod ($cDirectory, 0777);
?>
The $_POST variable is an array of variable names and values sent by the HTTP POST method.
PrintShop Web sends the XML stream in the PSW_XML POST variable. The script reads the value of
this variable and stores the data in a local variable.
The simplexml_load_string function is used to read the XML data and tto define the ID of the order.
The SimpleXML extension of PHP provides a set of functions to convert XML to an object that can be
processed with normal property selectors and array iterators. More information can be found at the
following url: http://www.php.net/simplexml
A xpath expression is used to retrieve a specific node of the XML order data (the fnOrderID element).
You can use the same method to retrieve any of the elements from the XML data and use it values
according to your needs.
At the end the XML data is written to a XML file using the order id as the file name.










