"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * TinyMCE Image uploader!
  4. */
  5. mb_internal_encoding("utf-8"); // Internal encoding set to UTF-8, should fix some charset issues.
  6. session_start(); // Start PHP session, so we can handle session-data on all pages.
  7. require_once("include.php");
  8. // Get working dir, and file path
  9. $cwd = getcwd();
  10. $imageFolder = $cwd . '/' . Config::$file_path;
  11. reset($_FILES);
  12. $temp = current($_FILES);
  13. if (is_uploaded_file($temp['tmp_name'])) {
  14. if (!User::checkLevel("75")) {
  15. header("HTTP/1.1 403 Origin Denied");
  16. return;
  17. }
  18. // Sanitize input
  19. if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
  20. header("HTTP/1.1 400 Invalid file name.");
  21. return;
  22. }
  23. // Verify extension
  24. if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), Config::$file_types)) {
  25. header("HTTP/1.1 400 Invalid extension.");
  26. return;
  27. }
  28. // Accept upload
  29. $filetowrite = $imageFolder . $temp['name'];
  30. move_uploaded_file($temp['tmp_name'], $filetowrite);
  31. // Respond to the successful upload with JSON.
  32. // Use a location key to specify the path to the saved image resource.
  33. // { location : '/your/uploaded/image/file'}
  34. echo json_encode(array('location' => Config::$sys_url . Config::$file_path . $temp['name']));
  35. } else {
  36. // Notify editor that the upload failed
  37. header("HTTP/1.1 500 Server Error");
  38. }