Skip to content

Commit 01b40ca

Browse files
committed
Remove file upload support
1 parent 8f44a4f commit 01b40ca

File tree

4 files changed

+5
-81
lines changed

4 files changed

+5
-81
lines changed

README.md

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ These features match features in v1 (see branch "v1"):
105105
- [x] Supports POST variables as input (x-www-form-urlencoded)
106106
- [x] Supports a JSON object as input
107107
- [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)~~
109109
- [ ] ~~Condensed JSON output: first row contains field names~~
110110
- [x] Sanitize and validate input using callbacks
111111
- [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
734734

735735
### File uploads
736736

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).
757738

758739
## OpenAPI specification
759740

examples/clients/upload/form.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Tqdev/PhpCrudApi/Middleware/FileUploadMiddleware.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Tqdev/PhpCrudApi/Request.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,10 @@ private function decodeBody(String $body) /*: ?object*/
9999

100100
private function parseBody(String $body = null) /*: void*/
101101
{
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');
111104
}
112-
$this->body = $object;
105+
$this->body = $this->decodeBody($body);
113106
}
114107

115108
public function getMethod(): String
@@ -187,9 +180,4 @@ public static function fromString(String $request): Request
187180
}
188181
return new Request($method, $path, $query, $headers, $body);
189182
}
190-
191-
public function getUploadedFiles(): array
192-
{
193-
return $_FILES;
194-
}
195183
}

0 commit comments

Comments
 (0)