浏览代码

Update to uploadhandler (tinymce)

tags/rls1
kenn408k 6 年前
父节点
当前提交
44f0d7d8c7
共有 1 个文件被更改,包括 6 次插入27 次删除
  1. 6
    27
      handleUpload.php

+ 6
- 27
handleUpload.php 查看文件

@@ -9,41 +9,19 @@ session_start(); // Start PHP session, so we can handle session-data on all page
9 9
 
10 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 13
 $cwd = getcwd();
21
-$imageFolder = $cwd .'/'. Config::$file_path;
14
+$imageFolder = $cwd . '/' . Config::$file_path;
22 15
 
23 16
 reset($_FILES);
24 17
 $temp = current($_FILES);
25 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 20
     if (!User::checkLevel("75")) {
37 21
         header("HTTP/1.1 403 Origin Denied");
38 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 25
     // Sanitize input
48 26
     if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
49 27
         header("HTTP/1.1 400 Invalid file name.");
@@ -51,19 +29,20 @@ if (is_uploaded_file($temp['tmp_name'])) {
51 29
     }
52 30
 
53 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 33
         header("HTTP/1.1 400 Invalid extension.");
56 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 38
     $filetowrite = $imageFolder . $temp['name'];
61 39
     move_uploaded_file($temp['tmp_name'], $filetowrite);
62 40
 
63 41
     // Respond to the successful upload with JSON.
64 42
     // Use a location key to specify the path to the saved image resource.
65 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 46
 } else {
68 47
     // Notify editor that the upload failed
69 48
     header("HTTP/1.1 500 Server Error");

正在加载...
取消
保存