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.
 
 
 
 
 
 

35 lines
904 B

<?php
namespace App\SearchDisplace\Convertor;
use Symfony\Component\Process\Process;
/**
* 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]);
$process->run();
return $path['filename'] . '.' . $to;
}
}