2

I'm trying to upload files to my laravel site using <input type="file"> yet it seems to be passing a string to the controller. I have this test to see if its a file yet I keep getting File not ok.

        if (Input::hasFile('file')) {
            dd('File ok');
        }
        dd('File not ok');

Any ideas? Thanks

3
  • 1
    Normally you would write that as if (Input::hasFile('file')) { dd('File ok'); } else { dd('File not ok'); } Commented Aug 27, 2018 at 15:13
  • 1
    You need a name on your input Commented Aug 27, 2018 at 15:13
  • @Devon it has a name. Sorry forgot to include it in the example. Commented Aug 29, 2018 at 12:12

1 Answer 1

12

this may be you're not setting your form to enctype="multipart/form-data", it should be like this

<form method="POST" action="/your/url" enctype="multipart/form-data">

Or maybe, your input has no name attribute like

<input type="file" name="file">
Sign up to request clarification or add additional context in comments.

2 Comments

I think it it the missing part of it was name Attribute laravel wont return a string
The missing enctype="multipart/form-data" did the trick. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.