Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.3 KiB

<?php
namespace App\SearchDisplace\Convertor;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
/**
* Convert documents from formats supported by Libre Office
*/
class Convertor {
/**
* @param $to desired file format
* @param $document absolute file path
* @param $tmp - if true file will be saved to tmp directory for download
*
* @return string $path to converted file
*/
public static function convert($to, $document, $tmp = false)
{
$path = pathinfo($document);
$dir = $path['dirname'];
$original = $dir . '/' . $path['basename'];
if(!$tmp) {
$folder = $dir . '/';
} else {
$folder = storage_path('app/tmp/');
}
$process = new Process(
[
'soffice',
'--convert-to',
$to,
$original,
'--outdir',
$folder
], base_path(),
[
'HOME' => base_path()
]
);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
return $path['filename'] . '.' . $to;
}
}