Overview
This article will provide an example of a PHP Script that parses out the information available in the Post URL call from the FileCatalyst Client Software/API. The URL call uses a POST command to send the list of files. It needs to be run from an Apache Tomcat Web Server with PHP Script on the same box as the Client Software/API.
Environment
FileCatalyst Client Software/API v3.5 and later.
Apache Web Server with PHP v5.0 or later.
Resolution
This method can be used for various FileCatalyst Client Applications. The following is a HotFolder Example:
- Create a scheduled task in the FileCatalyst HotFolder.
- Go to the Post Task tab and under the Post URL field call the following URL, replacing the information between the <>:
http://<HostIP_Address>:<Port>/<PHPScript_Name>.php
- The following sample script will write the contents to a file located in c:/temp/succeeded.txt. This path can be changed by modifying the $fileOutput parameter in the script.
Sample PHP Script:
<html>
<?php
/* Script to Output File Names Received By FileCatalyst HotFolder Author: John Tkaczewski */
$filePostVariable = 'f'; //The POST variable containing the file listing no paths of only successful transfers
$filePathPostVariable = 'lf'; //The POST variable containing the file listing with full paths of only successful transfers
$fileSizesPostVariable = 's'; //The POST variable containing the file sizes
$fileStatusPostVariable = 'status'; //The POST variable containing the status for each file, see HF docs
$fileAllFilesPostVariable = 'allfiles'; //The POST variable containing the file listing with full paths including files scheduled to be transferred and that failed to transfer
$fileDelimiter = '|'; //The delimiter that seperates the file list, it's a pipe by default and can't be chnaged
$fileOutput = 'c:/temp/succeeded.txt'; //The file location to write the file list
//Initialize the output variable
$outputData = '';
//Break the file list into an array
$filePost = $_POST[$filePostVariable];
$filePost = explode($fileDelimiter, $filePost);
$outputData .= "\n***** f parameter values****\n";
if (is_array($filePost)) {
//Loop through the file list
foreach ($filePost as $tmp) {
//Reverse the string for tokenizing purposes
$tmp = strrev($tmp);
//Tokenize the string
$fileName = strtok($tmp, "\\/");
if ($fileName) {
//If a filename exists, reverse it back to original state
$fileName = strrev($fileName);
//Append the filename to the output variable
$outputData .= $fileName . "\r\n";
}
}
}
$outputData .= "\n***** lf parameter values****\n";
//Break the file list with paths into an array
$filePost = $_POST[$filePathPostVariable];
$filePost = explode($fileDelimiter, $filePost);
if (is_array($filePost)) {
//Loop through the file list
foreach ($filePost as $tmp) {
//Reverse the string for tokenizing purposes
$tmp = strrev($tmp);
//Tokenize the string
$fileName = strtok($tmp, "\\/");
if ($fileName) {
//If a filename exists, reverse it back to original state
$fileName = strrev($fileName);
//Append the filename to the output variable
$outputData .= $fileName . "\r\n";
}
}
}
$outputData .= "\n***** s parameter values****\n";
//Break the file sizes into an array
$filePost = $_POST[$fileSizesPostVariable];
$filePost = explode($fileDelimiter, $filePost);
if (is_array($filePost)) {
//Loop through the file list
foreach ($filePost as $tmp) {
//Reverse the string for tokenizing purposes
$tmp = strrev($tmp);
//Tokenize the string
$fileName = strtok($tmp, "\\/");
if ($fileName) {
//If a filename exists, reverse it back to original state
$fileName = strrev($fileName);
//Append the filename to the output variable
$outputData .= $fileName . "\r\n";
}
}
}
$outputData .= "\n***** status parameter values****\n";
//Break the file status into an array
$filePost = $_POST[$fileStatusPostVariable];
$filePost = explode($fileDelimiter, $filePost);
if (is_array($filePost)) {
//Loop through the file list
foreach ($filePost as $tmp) {
//Reverse the string for tokenizing purposes
$tmp = strrev($tmp);
//Tokenize the string
$fileName = strtok($tmp, "\\/");
if ($fileName) {
//If a filename exists, reverse it back to original state
$fileName = strrev($fileName);
//Append the filename to the output variable
$outputData .= $fileName . "\r\n";
}
}
}
$outputData .= "\n***** allfiles parameter values****\n";
//Break the file allfiles into an array
$filePost = $_POST[$fileAllFilesPostVariable];
$filePost = explode($fileDelimiter, $filePost);
if (is_array($filePost)) {
//Loop through the file list
foreach ($filePost as $tmp) {
//Reverse the string for tokenizing purposes
$tmp = strrev($tmp);
//Tokenize the string
$fileName = strtok($tmp, "\\/");
if ($fileName) {
//If a filename exists, reverse it back to original state
$fileName = strrev($fileName);
//Append the filename to the output variable
$outputData .= $fileName . "\r\n";
}
}
}
//Create and/or open the file with write permissions
$handle = fopen($fileOutput, 'w');
//Flush the output to the file
fputs($handle, trim($outputData));
//Close the file
fclose($handle);
/* End Script */
?>
<html>
<!--The HotFolder/Server ignores the response from the server. There is no need to redirect or output
anything besides the empty HTML tag-->
</html>
- Save the script above with the extension of PHP and use the saved filename in step 2.
|