Document toolboxDocument toolbox

(2024.2) Creating Inbound/Outbound Files

createFile

Users can use Custom Logic to create files directly onto the Inbound/Outbound directories for processing either by internal processes (Inbound) or external processes (Outbound).

int|false createFile( string $filename, string|array $content, string $location = 'OUTBOUND', bool $overwrite = false )

Parameters

$filename: The name of the file to create. Any path will be ignored; just the basename used

$content: The data to write to the file. String data will be written as is and arrays will be written as if implode('', $content)

$location: The location in which to create the file. Supported values are INBOUND and OUTBOUND; any other value should cause the function to return false after logging an error. The default is ‘OUTBOUND’

$overwrite: A boolean flag that determines if an existing file with the same name will be overwritten. The default is false.

Return Values

The function returns an integer number of bytes written to the file upon success or a boolean false upon failure.

Notes

  • If the location is not supported, it will log an error and return false

  • If the overwrite is false and the file exists, it will log an error and return a false

  • If the location does not exist, it will be created

  • If an error occurs while writing the file, the error will be logged, and false will be returned

  • When the file is successfully written, the number of bytes written will be returned

Example

// Example $bytesWritten = $this->createFile('MY-OUTBOUND-FILE.csv', $csv , 'OUTBOUND', true); if ($bytesWritten === false) { // There was an error creating the file, handle that here // Check the error log for more details } else { // The file was created successfully $bytesWritten will be the number of bytes written }