Browse Source

Update to uploadhandler (tinymce)

tags/rls1
kenn408k 6 years ago
parent
commit
44f0d7d8c7
1 changed files with 6 additions and 27 deletions
  1. 6
    27
      handleUpload.php

+ 6
- 27
handleUpload.php View File

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

Loading…
Cancel
Save