-
Notifications
You must be signed in to change notification settings - Fork 1
/
bibtexhandler.php
77 lines (65 loc) · 2.13 KB
/
bibtexhandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
session_start(['cookie_lifetime' => 86400]);
// file upload handler for BibTex files
include "getnewid.php";
$errorMsg = "";
$sysMsg = "";
$uploadType = "file";
$filePath = "";
$testingLevel = 0;
$id = 0;
$fileContents = "";
// get folder info
$isDirSet = false;
if ( ! isset ( $_SESSION_['folder_id'] ) ) {
$idErr = GetNewId();
if ( strlen($idErr) > 0 ) {
$errorMsg .= $idErr;
} else {
$isDirSet = true;
}
}
if ( ! $isDirSet ) {
$errorMsg .= "<p>Error creating new id.</p>\n";
} else if ( $testingLevel > 1 ) {
$sysMsg .= "<p>(bib) Folder ID: " . $_SESSION['folder_id'] . "</p>\n";
}
if ( $isDirSet ) {
$id = $_SESSION['folder_id'];
$path = 'output/' . $id;
// actual file upload. Do we have an actual file, or text?
if ( empty($_FILES) ) {
// manual save from the textarea
$uploadType = "textarea";
if ( isset ( $_POST['fileName'] ) ) {
$filePath = $path . '/' . $_POST['fileName'];
$file = fopen($filePath , 'w');
fwrite($file, $_POST['textarea']);
fclose($file);
$fileContents = $_POST['textarea'];
} else {
$errorMsg .= "<p>Failed to save manually entered text</p>\n";
}
} else {
// actual file upload
if ( 0 < $_FILES['file']['error'] || $id == 0 ) {
$errorMsg .= "Error uploading this file. ";
if ( $testingLevel > 0 ) {
$errorMsg .= "<p>ID: $id</p>\n";
$errorMsg .= $_FILES['file']['error'] . '<br>';
}
} else {
if ( ! is_dir($path) ) {
mkdir($path);
}
$filePath = $path . '/' . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $filePath);
$fileContents = file_get_contents($filePath);
}
}
}
$filePath = __DIR__ . "/" . $filePath;
$filePath = str_replace("\\", "/", $filePath);
$outputData = array("error" => $errorMsg, "ID" => $id, "message" => $sysMsg, "filePath" => $filePath, "uploadType" => $uploadType, "fileContents" => $fileContents);
echo json_encode($outputData);
?>