The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Accessing FormData data from $request

John Smith's Avatar

John Smith

04 Feb, 2016 04:37 PM

I'm trying to upload files via AJAX call to a route.

The file is uploaded via FormData object embedded into the ajax call like so :

$.ajax({
method: 'POST',
data: formdata
... })

I can access the non 'file' data, such as simple key, value pairs using ' $request->getParsedBody() ' but cannot access the file, in this case an image.

And I know that the image file is being sent because when I check the 'network' information in my developer console, the file is part of the request body.

Also the $_FILES array is empty. $_POST array doesn't contain files.

  1. 1 Posted by John Smith on 05 Feb, 2016 11:54 PM

    John Smith's Avatar

    Answer to myself:

    $request->getUploadedFiles();

  2. 2 Posted by alan on 27 Mar, 2020 02:15 PM

    alan's Avatar

    Thank you!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac