Help with Slim form

0 votes
asked May 25, 2016 in Slim by Saravanan

Hi, I'm noob to this framework. Trying new when I get some time in between. Please help me out with the below.

For posting from a form I do the following

$email = $app->request->post('email');

So, how can I post an image into a variable? I mean, how to receive an image from a form?

Please also let me know if any good tutorials are available for this online?

Thanks in advance.

1 Answer

0 votes
answered May 25, 2016 by Shamnadh

$app->post('/upload', function ($request, $response, $args) {
    $files = $request->getUploadedFiles();
    if (empty($files['newfile'])) {
        throw new Exception('Expected a newfile');

    $newfile = $files['newfile'];
    // do something with $newfile

To check that there is no error and to move the file to some other location, use this checking:
if ($newfile->getError() === UPLOAD_ERR_OK) {
    $uploadFileName = $newfile->getClientFilename();

There are other useful methods like getClientMediaType() and getSize() also. Please use as per your needs.

Related questions

+2 votes
1 answer 366 views
asked Feb 9, 2017 in General by Marc Lentin
0 votes
1 answer 1176 views
0 votes
1 answer 51 views
asked Aug 19, 2016 in General by Azi Graeber
0 votes
1 answer 262 views
asked Jul 11, 2016 in Magento by Graham G
0 votes
1 answer 39 views