I have an external library with a bunch of executables (DCMTK). Normally, those can be executed on the CLI, with output sometimes showing in the terminal. I want to use some of those in PHP scripts, and I was able to do that with one.
Essentials are:
// path to the executables.
private static $dcmtk_path = '/usr/local/opt/dcmtk/bin/';
//method to execute the dcmtk executable.
public static function dcmtk_command($command) {
//--logfile dcmlogfile.cfg
echo exec(self::$dcmtk_path . $command); // $outputarray, 2nd arg ?
}
}
// working example that converts a text file to a dcm worklist file
file_put_contents (self::$MWL_PATH . "samplephp.txt", $template); // text file for MWL.
echo '[{"status":"Sent to PATH"}]';
self::dcmtk_command('dump2dcm ' . self::$MWL_PATH . "samplephp.txt " . self::$MWL_PATH . "samplephp.wl");
I don't know if this is even possible. But, I am uploading multiple files via a $_POST and get:
$file_tmp = $files['tmp_name'];
That is saved to a path on the server:
$success = move_uploaded_file($file_tmp, $upload_path);
and then I want to execute another command:
self::dcmtk_command('dcmdump ' . $upload_path . $file_name );
// dcmdump +P StudyInstanceUID IM-0001-0004.dcm for specific tag
When executed from the CLI that prints out a bunch of text to the terminal (?STDOUT). What I want to do is capture that output in the PHP script so that I can process the output. I have tried a few things, like using an output buffer, the $outputarray from the exec command, etc.
Seems like that should be possible. The files are getting saved on the server in the path that is configured, so they should be at $upload_path . $file_name. And, I do not see any errors in the PHP console / error log. I actually do not have a good way to check if the command was even successful.