Skip to content

Commit

Permalink
Remove file upload support
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Oct 21, 2018
1 parent 8f44a4f commit 01b40ca
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 81 deletions.
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ These features match features in v1 (see branch "v1"):
- [x] Supports POST variables as input (x-www-form-urlencoded)
- [x] Supports a JSON object as input
- [x] Supports a JSON array as input (batch insert)
- [x] Supports file upload from web forms (multipart/form-data)
- [ ] ~~Supports file upload from web forms (multipart/form-data)~~
- [ ] ~~Condensed JSON output: first row contains field names~~
- [x] Sanitize and validate input using callbacks
- [x] Permission system for databases, tables, columns and records
Expand Down Expand Up @@ -734,26 +734,7 @@ The above example will add a header "X-Time-Taken" with the number of seconds th

### File uploads

The 'fileUpload' middleware allows you to upload a file using a web form (multipart/form-data) like this:

```
<form method="post" action="http://localhost/api.php/records/categories" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="icon">
<input type="submit">
</form>
```

Then this is handled as if you would have sent:

```
POST http://localhost/api.php/records/categories
{"icon_name":"not.gif","icon_type":"image\/gif","icon":"ZGF0YQ==","icon_error":0,"icon_size":4}
```

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

NB: You cannot edit a file using this method, because browsers do not support the "PUT" method in these forms.
File uploads are supported through the [FileReader API](https://caniuse.com/#feat=filereader).

## OpenAPI specification

Expand Down
12 changes: 0 additions & 12 deletions examples/clients/upload/form.html

This file was deleted.

33 changes: 0 additions & 33 deletions src/Tqdev/PhpCrudApi/Middleware/FileUploadMiddleware.php

This file was deleted.

18 changes: 3 additions & 15 deletions src/Tqdev/PhpCrudApi/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,10 @@ private function decodeBody(String $body) /*: ?object*/

private function parseBody(String $body = null) /*: void*/
{
if ($body) {
$object = $this->decodeBody($body);
} else {
if (!empty($_FILES)) {
$object = (object) $_POST;
} else {
$input = file_get_contents('php://input');
$object = $this->decodeBody($input);
}
if (!$body) {
$body = file_get_contents('php://input');
}
$this->body = $object;
$this->body = $this->decodeBody($body);
}

public function getMethod(): String
Expand Down Expand Up @@ -187,9 +180,4 @@ public static function fromString(String $request): Request
}
return new Request($method, $path, $query, $headers, $body);
}

public function getUploadedFiles(): array
{
return $_FILES;
}
}

0 comments on commit 01b40ca

Please sign in to comment.