"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

handleUpload.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /* * *************************************************
  9. * Only these origins are allowed to upload images *
  10. * ************************************************* */
  11. $accepted_origins = array("http://localhost", "https://localhost", "https://127.0.0.1", "http://127.0.0.1");
  12. /* * *******************************************
  13. * Change this line to set the upload folder *
  14. * ******************************************* */
  15. $cwd = getcwd();
  16. $imageFolder = $cwd .'/'. Config::$file_path;
  17. reset($_FILES);
  18. $temp = current($_FILES);
  19. if (is_uploaded_file($temp['tmp_name'])) {
  20. /* if (isset($_SERVER['HTTP_ORIGIN'])) {
  21. // same-origin requests won't set an origin. If the origin is set, it must be valid.
  22. if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) {
  23. header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
  24. } else {
  25. header("HTTP/1.1 403 Origin Denied");
  26. return;
  27. }
  28. } */
  29. if (!User::checkLevel("75")) {
  30. header("HTTP/1.1 403 Origin Denied");
  31. return;
  32. }
  33. /*
  34. If your script needs to receive cookies, set images_upload_credentials : true in
  35. the configuration and enable the following two headers.
  36. */
  37. // header('Access-Control-Allow-Credentials: true');
  38. // header('P3P: CP="There is no P3P policy."');
  39. // Sanitize input
  40. if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
  41. header("HTTP/1.1 400 Invalid file name.");
  42. return;
  43. }
  44. // Verify extension
  45. if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) {
  46. header("HTTP/1.1 400 Invalid extension.");
  47. return;
  48. }
  49. // Accept upload if there was no origin, or if it is an accepted origin
  50. $filetowrite = $imageFolder . $temp['name'];
  51. move_uploaded_file($temp['tmp_name'], $filetowrite);
  52. // Respond to the successful upload with JSON.
  53. // Use a location key to specify the path to the saved image resource.
  54. // { location : '/your/uploaded/image/file'}
  55. echo json_encode(array('location' => Config::$sys_url.Config::$file_path.$temp['name']));
  56. } else {
  57. // Notify editor that the upload failed
  58. header("HTTP/1.1 500 Server Error");
  59. }