bestmomo's avatar

[L5] Get input from file upload

Hello,

With L5 I have a strange thing about getting uploaded file from a form. When I use :

Request::input('image')

I have a NULL value. I have to write :

Request::all()['image']

to get it...

Any idea ?

0 likes
4 replies
bashy's avatar

Yeah ::input() reads $_REQUEST - $_POST - $_GET

::file() reads $_FILES :)

Or at least it was in L4

nolros's avatar

@bestmono

This is how I have it setup in L5 for my files upload. I think Request::all() gets you file info as to location in the server. What that means is you can do a $Request:all() and then based on the Apache server path and temp file name you could then do a File::get($path), but rather just use Request::file().

if (Request::hasFile('file'))
{
    $allFiles = Request::file('file');
    // if multi file upload then it will be array, write to an array 
    if (!is_array($allFiles))
    {
        $allFiles = array($allFiles);
    }
}

// foreach through each file
1 like

Please or to participate in this conversation.