"ERR","message"=>"Empty type"]); exit;}
if (array_search($type, $allowed_types) === false) {print json_encode(["status"=>"ERR","message"=>"Invalid type"]); exit;}
if (preg_match("/\.([^\.]*)$/", $_FILES['userfile']['name'], $r)) {
$name_tmp=preg_replace("![\.]!","-",time().".".uniqid(null,true));
if (array_search(strtolower($r[1]), $allowed_ext) === false) {print json_encode(["status"=>"ERR","message"=>"Invalid src ext"]); exit;}
$src=$uploaddir."/".$name_tmp.".".$r[1];
$dst=$uploaddir."/".$name_tmp.".".$type;
move_uploaded_file($_FILES['userfile']['tmp_name'], $src);
exec("/usr/bin/unoconv -n -f ".$type." -o '".$dst."' '".$src."'",$res,$code);
if ($code ==0) {
exec("rm -f ".$src);
} else {
exec("rm -f $src");
exec("rm -f $dst");
print json_encode(["status"=>"ERR","message"=>"Converter error. Code $code"]);
exit;
}
} else {
print json_encode(["status"=>"ERR","message"=>"Invalid src filename"]);
exit;
}
if ($rtype=='html') {
print "$name_tmp.$type";
} else {
print json_encode(["status"=>"OK","result"=>"/files/".$name_tmp.".".$type]);
}
?>