storage_path('app/' . env('LIBREOFFICE_CONFIG_PATH', 'tmp/libreoffice')), ]; if ($extension == 'odt') { $to = $to . ':"${:FILTER}"'; $env['FILTER'] = 'OpenDocument Text Flat XML'; } Log::info('Running `soffice` to convert "' . $original . '" to "' . $to . '". Output folder: "' . $folder . '"'); Log::info( 'COMMAND: ' . 'soffice ' . '--convert-to ' . $to . ' ' . $original . ' ' . '--outdir ' . $folder ); # We will run the process from a shell command line, which allows us to add parameters # The "OpenDocument Text Flat XML" parameter contains whitespaces, so we will need to add that as # a env variable parameter, otherwise the Process class will escape it and it will not work properly. $process = Process::fromShellCommandline( "soffice --convert-to $to $original --outdir $folder", null, //base_path(), $env ); $process->run(function ($type, $buffer) { if (Process::ERR === $type) { Log::info("CONVERT ERROR: " . $buffer); } }, $env); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } Storage::deleteDirectory(env('LIBREOFFICE_CONFIG_PATH', 'app/tmp/libreoffice')); return $path['filename'] . '.' . $to; } }