Spreadsheet Converter
[insert_php]
session_start();
if ($_FILES[“upload”][“error”] > 0)
{
echo ”
Error: ” . $_FILES[“upload”][“error”] . ”
\n”;
}
$_SESSION[‘tmpFileName’] = $temp_file_name = $_FILES[‘upload’][‘tmp_name’];
$_SESSION[‘file’] = [];
$_SESSION[‘fileName’] = $_FILES[‘upload’][‘name’];
$_SESSION[‘source’] = $_REQUEST[‘source’];
$_SESSION[‘target’] = $_REQUEST[‘target’];
$_SESSION[‘license’] = $_REQUEST[‘license’];
$_SESSION[‘creator’] = $_REQUEST[‘creator’];
$_SESSION[‘description’] = $_REQUEST[‘description’];
$_SESSION[‘license’] = $_REQUEST[‘license’];
$_SESSION[‘directionality’] = $_REQUEST[‘directionality’];
$_SESSION[‘subject’] = $_REQUEST[‘subject’];
$_SESSION[‘dict_id’] = $_REQUEST[‘dict_id’];
$out_file_name = ‘./scripts/perl_errors.txt’;
##$perl = ‘perl’;
$perl = “~/.plenv/versions/5.22.1/bin/perl”;
$perl_lib=’-I ./scripts/Convert-Spreadsheet-TBXmin-0.02/lib/’;
$script = ‘./scripts/Convert-Spreadsheet-TBXmin-0.02/lib/Convert/TBX/Config.pm’;
#set this to true when you put it on byuling.
$onServer = true;
if($onServer){
$perl_lib .= ‘ -I /home2/gevtermn/perl5/lib/perl5’;
}
# stderr gets sent to file in case it’s needed
$rerouteIO = “2> $out_file_name”;
# TODO: probably don’t need to print to file
# and then serve the file…
$output_file_name = $temp_file_name . ‘.tbxm’;
$command = “$perl $perl_lib $script ” .
escapeshellarg($temp_file_name) . ‘ ‘ .
escapeshellarg($_REQUEST[‘source’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘target’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘license’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘creator’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘description’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘license’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘directionality’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘subject’]) . ‘ ‘ .
escapeshellarg($_REQUEST[‘dict_id’]) . ‘ ‘ .
escapeshellarg($_SESSION[‘fileName’]) . ‘ ‘ .
“$rerouteIO”;
$ret_val = 0;
exec($command, $printed_output, $ret_val);
$file_contents = split(“====NEWLINE====”,$printed_output[0]);
if(($ret_val != 0) || (!file_exists($out_file_name)) ){
header(‘HTTP/1.1 400 Bad Request’);
ob_clean();
flush();
readfile($out_file_name);
}else
{
}
[/insert_php]
TBX Convert | Spreadsheet