Преглед изворни кода

Remove file upload support

Maurits van der Schee пре 5 година
родитељ
комит
01b40cadc7

+ 2
- 21
README.md Прегледај датотеку

@@ -105,7 +105,7 @@ These features match features in v1 (see branch "v1"):
105 105
   - [x] Supports POST variables as input (x-www-form-urlencoded)
106 106
   - [x] Supports a JSON object as input
107 107
   - [x] Supports a JSON array as input (batch insert)
108
-  - [x] Supports file upload from web forms (multipart/form-data)
108
+  - [ ] ~~Supports file upload from web forms (multipart/form-data)~~
109 109
   - [ ] ~~Condensed JSON output: first row contains field names~~
110 110
   - [x] Sanitize and validate input using callbacks
111 111
   - [x] Permission system for databases, tables, columns and records
@@ -734,26 +734,7 @@ The above example will add a header "X-Time-Taken" with the number of seconds th
734 734
 
735 735
 ### File uploads
736 736
 
737
-The 'fileUpload' middleware allows you to upload a file using a web form (multipart/form-data) like this:
738
-
739
-```
740
-<form method="post" action="http://localhost/api.php/records/categories" enctype="multipart/form-data">
741
-  Select image to upload:
742
-  <input type="file" name="icon">
743
-  <input type="submit">
744
-</form>
745
-```
746
-
747
-Then this is handled as if you would have sent:
748
-
749
-```
750
-POST http://localhost/api.php/records/categories
751
-{"icon_name":"not.gif","icon_type":"image\/gif","icon":"ZGF0YQ==","icon_error":0,"icon_size":4}
752
-```
753
-
754
-As you can see the "xxx_name", "xxx_type", "xxx_error" and "xxx_size" meta fields are added (where "xxx" is the name of the file field).
755
-
756
-NB: You cannot edit a file using this method, because browsers do not support the "PUT" method in these forms.
737
+File uploads are supported through the [FileReader API](https://caniuse.com/#feat=filereader).
757 738
 
758 739
 ## OpenAPI specification
759 740
 

+ 0
- 12
examples/clients/upload/form.html Прегледај датотеку

@@ -1,12 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-<body>
4
-
5
-<form action="api.php/records/categories" method="post" enctype="multipart/form-data">
6
-    <input type="text" name="name" value="upload">
7
-    <input type="file" name="icon">
8
-    <input type="submit" value="upload">
9
-</form>
10
-
11
-</body>
12
-</html>

+ 0
- 33
src/Tqdev/PhpCrudApi/Middleware/FileUploadMiddleware.php Прегледај датотеку

@@ -1,33 +0,0 @@
1
-<?php
2
-namespace Tqdev\PhpCrudApi\Middleware;
3
-
4
-use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
5
-use Tqdev\PhpCrudApi\Request;
6
-use Tqdev\PhpCrudApi\Response;
7
-
8
-class FileUploadMiddleware extends Middleware
9
-{
10
-    public function handle(Request $request): Response
11
-    {
12
-        $files = $request->getUploadedFiles();
13
-        if (!empty($files)) {
14
-            $body = $request->getBody();
15
-            foreach ($files as $fieldName => $file) {
16
-                if (isset($file['error']) && $file['error']) {
17
-                    return $this->responder->error(ErrorCode::FILE_UPLOAD_FAILED, $fieldName);
18
-                }
19
-                foreach ($file as $key => $value) {
20
-                    if ($key == 'tmp_name') {
21
-                        $value = base64_encode(file_get_contents($value));
22
-                        $key = $fieldName;
23
-                    } else {
24
-                        $key = $fieldName . '_' . $key;
25
-                    }
26
-                    $body->$key = $value;
27
-                }
28
-            }
29
-            $request->setBody($body);
30
-        }
31
-        return $this->next->handle($request);
32
-    }
33
-}

+ 3
- 15
src/Tqdev/PhpCrudApi/Request.php Прегледај датотеку

@@ -99,17 +99,10 @@ class Request
99 99
 
100 100
     private function parseBody(String $body = null) /*: void*/
101 101
     {
102
-        if ($body) {
103
-            $object = $this->decodeBody($body);
104
-        } else {
105
-            if (!empty($_FILES)) {
106
-                $object = (object) $_POST;
107
-            } else {
108
-                $input = file_get_contents('php://input');
109
-                $object = $this->decodeBody($input);
110
-            }
102
+        if (!$body) {
103
+            $body = file_get_contents('php://input');
111 104
         }
112
-        $this->body = $object;
105
+        $this->body = $this->decodeBody($body);
113 106
     }
114 107
 
115 108
     public function getMethod(): String
@@ -187,9 +180,4 @@ class Request
187 180
         }
188 181
         return new Request($method, $path, $query, $headers, $body);
189 182
     }
190
-
191
-    public function getUploadedFiles(): array
192
-    {
193
-        return $_FILES;
194
-    }
195 183
 }

Loading…
Откажи
Сачувај