SEUNGMUN's avatar

L5 File Request

Hi guys.

I have a problem to upload some image file via ajax. even not ajax(just post form).

Request instance allows to get all request type, but it doesn't allow file types. input[type=text] returns its own value (include csrf _token field).

but input[type=file] returns nothing.

however, I can get this file request via $_FILES global variable.

what is the problem? it makes me annoy.

someone give me a solution to solve it.

lastly, I am really sorry for my useless English.

0 likes
13 replies
bestmomo's avatar

Did you set the file type in your form ? 'files' => true or enctype="multipart/form-data" in raw mode.

And you have to get the file with $request->file(...)

SEUNGMUN's avatar

@blackbird it has enctype attribute with multipart value.

when I use 'Reqeust::file('image')', nothing returns.

but using '$_FILES['image']' it returns an array of uploaded file.

SEUNGMUN's avatar

@bestmomo

Yes I set the file type in my form.

<form id="uploadForm" action="/board/image" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="file" name="image">
    <button type="submit">Submit</button>
</form>
// Result : {"image":{"name":"test.jpg","type":"image\/jpeg","tmp_name":"\/tmp\/1nPHq1","error":0,"size":126456}}
$foo = $_FILES['image'];
// Result : Nothing.
$foo2 = Request::file('image');
bestmomo's avatar

Is it a fresh L5 ? Because your code is correct...

SEUNGMUN's avatar

@bestmomo If it's a server issue, I think '$_FILES['image']' should not be work.

Should I shift to ensure in a different environment?

bobbybouwmann's avatar

What server setup do you use? Maybe it's a dependency or something, idk!

bobbybouwmann's avatar

Mmh that's weird... And if you run homestead update and composer update any problems after that?

Please or to participate in this conversation.