UB-Mannheim /
PalMA
| 1 | <?php |
||
| 2 | |||
| 3 | require_once 'globals.php'; |
||
| 4 | debug('upload.php: begin'); |
||
| 5 | |||
| 6 | // This action requires an authorized user. |
||
| 7 | require_once 'auth.php'; |
||
| 8 | |||
| 9 | if (empty($_FILES)) { |
||
| 10 | $error = 99; |
||
| 11 | $filename = 'unknown'; |
||
| 12 | } else { |
||
| 13 | $error = $_FILES['file']['error']; |
||
| 14 | $filename = $_FILES['file']['name']; |
||
| 15 | } |
||
| 16 | |||
| 17 | if (!is_dir(CONFIG_UPLOAD_DIR)) { |
||
| 18 | /* Target directory is missing, so create it now. */ |
||
| 19 | mkdir(CONFIG_UPLOAD_DIR, 0755, true); |
||
| 20 | } |
||
| 21 | |||
| 22 | if ($error == UPLOAD_ERR_OK || $error == "downloaded_from_url") { |
||
| 23 | # All uploaded files are collected in the upload directory. |
||
| 24 | # If necessary, an index is added to get a unique filename. |
||
| 25 | $tempFile = $_FILES['file']['tmp_name']; |
||
| 26 | $targetFile = CONFIG_UPLOAD_DIR . "/$filename"; |
||
| 27 | $index = 0; |
||
| 28 | $fparts = pathinfo($filename); |
||
| 29 | $fname = $fparts['filename']; |
||
| 30 | $ftype = null; |
||
| 31 | if (isset($fparts['extension'])) { |
||
| 32 | $ftype = $fparts['extension']; |
||
| 33 | } |
||
| 34 | while (file_exists($targetFile)) { |
||
| 35 | $index++; |
||
| 36 | if ($ftype) { |
||
| 37 | $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index.$ftype"; |
||
| 38 | } else { |
||
| 39 | $targetFile = CONFIG_UPLOAD_DIR . "/$fname-$index"; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | debug("upload.php: '$tempFile' to '$targetFile'"); |
||
| 43 | if (is_uploaded_file($tempFile)) { |
||
| 44 | move_uploaded_file($tempFile, $targetFile); |
||
| 45 | } elseif ($error == "downloaded_from_url") { |
||
| 46 | rename($tempFile, $targetFile); |
||
| 47 | } else { |
||
| 48 | trace("upload.php: upload failed!"); |
||
| 49 | } |
||
| 50 | } else { |
||
| 51 | // Support localisation. |
||
| 52 | require_once 'i12n.php'; |
||
| 53 | |||
| 54 | $targetFile = CONFIG_UPLOAD_DIR . "/error.html"; |
||
| 55 | $f = fopen($targetFile, 'w'); |
||
| 56 | if ($f) { |
||
| 57 | switch ($error) { |
||
| 58 | case UPLOAD_ERR_INI_SIZE: |
||
| 59 | $message = addslashes(__("This file is too large.")); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 60 | break; |
||
| 61 | case UPLOAD_ERR_FORM_SIZE: |
||
| 62 | $message = addslashes(__("Large files are not supported.")); |
||
| 63 | break; |
||
| 64 | case UPLOAD_ERR_PARTIAL: |
||
| 65 | $message = addslashes(__("File was only partially uploaded.")); |
||
| 66 | break; |
||
| 67 | default: |
||
| 68 | $message = sprintf(addslashes(__("Error code %s.")), $error); |
||
| 69 | break; |
||
| 70 | } |
||
| 71 | fprintf($f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""); |
||
| 72 | fprintf($f, "\"http://www.w3.org/TR/html4/strict.dtd\">"); |
||
| 73 | fprintf($f, "<html>\n"); |
||
| 74 | fprintf($f, "<head>\n"); |
||
| 75 | fprintf($f, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); |
||
| 76 | fprintf($f, "<title>Error</title>\n"); |
||
| 77 | fprintf($f, "</head>\n"); |
||
| 78 | fprintf($f, "<body>\n"); |
||
| 79 | fprintf($f, "<p>\n"); |
||
| 80 | fprintf( |
||
| 81 | $f, |
||
| 82 | addslashes(__("File '%s' cannot be shown.")) . "<br>\n%s\n", |
||
| 83 | $filename, |
||
| 84 | $message |
||
| 85 | ); |
||
| 86 | fprintf($f, "</p>\n"); |
||
| 87 | fprintf($f, "</body>\n"); |
||
| 88 | fprintf($f, "</html>\n"); |
||
| 89 | fclose($f); |
||
| 90 | } |
||
| 91 | $targetFile = "file:///$targetFile"; |
||
| 92 | } |
||
| 93 | |||
| 94 | // create window object and send to nuc |
||
| 95 | |||
| 96 | $dt = new DateTime(); |
||
| 97 | $date = $dt->format('Y-m-d H:i:s'); |
||
| 98 | |||
| 99 | $window = array( |
||
| 100 | "id" => "", |
||
| 101 | "win_id" => "", |
||
| 102 | "name" => "", |
||
| 103 | "state" => "", |
||
| 104 | "file" => $targetFile, |
||
| 105 | "userid" => "", |
||
| 106 | "date" => $date); |
||
| 107 | |||
| 108 | //echo "<body onLoad=\"sendToNuc('newWindow=".serialize($window)."')\" /></body>"; |
||
| 109 | |||
| 110 | $serializedWindow = serialize($window); |
||
| 111 | |||
| 112 | $sw = urlencode($serializedWindow); |
||
| 113 | // Get cURL resource |
||
| 114 | $curl = curl_init(); |
||
| 115 | // Set some options - we are passing in a useragent too here |
||
| 116 | curl_setopt_array($curl, array( |
||
| 117 | CURLOPT_RETURNTRANSFER => 1, |
||
| 118 | CURLOPT_URL => CONFIG_CONTROL_FILE . '?newWindow=' . $sw, |
||
| 119 | CURLOPT_USERAGENT => 'PalMA cURL Request' |
||
| 120 | )); |
||
| 121 | // Send the request & save response to $resp |
||
| 122 | $resp = curl_exec($curl); |
||
| 123 | // Close request to clear up some resources |
||
| 124 | curl_close($curl); |
||
| 125 | |||
| 126 | debug("upload.php: upload closed, result='$resp'"); |
||
| 127 |