Files
BS_Tools/SheetCheckingTool/upload.php
T
2020-12-02 14:21:46 +01:00

86 lines
1.9 KiB
PHP

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// allow certain file formats
if ($imageFileType != "pdf") {
echo "Sorry, only PDF files are allowed.";
$uploadOk = 0;
}
// check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// otherwise upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
// process file
$output = shell_exec("java -jar TaskSheetChecker.jar " . $target_dir . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])));
$keySeparator = ',';
$delimiter = ';';
$key_array = array();
$value_array = array();
$currentString = "";
for ($i = 0; $i < strlen($output); $i++) {
if ($output[$i] == ',') {
array_push($key_array, $currentString);
$currentString = "";
} else if ($output[$i] == ';') {
array_push($value_array, $output[$i]);
$currentString = "";
} else {
$currentString = $currentString . $output[$i];
}
}
echo count($key_array) . "<br>";
echo count($value_array);
foreach ($value_array as &$value)
echo $value . "<br>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Upload PDF</title>
</head>
<body>
<?php
// TODO: php code goes here
?>
</body>
</html>