0

I have this form

<form class="" enctype="multipart/form-data" action="{{route('submit_prop')}}" method="POST">
<div class="margin-btm-sm">
    <label>Main Image</label>
    <input type="file" name="main_img" class="form-control" />
</div>

  <div class="margin-btm-sm">
    <button type="submit" class="btn btn-primary">Save</button>
</div>
</form>

when submit the form the request array (POST array) is empty. but when remove enctype="multipart/form-data" from form

<form class="" action="{{route('submit_prop')}}" method="POST">

the request array has data.

Controller Method:

   function submit(SubmitPropRequest $request, $id=null) {
              dd(\Request::all());
   }

Request Contoller:

 public function rules()
{  
         dd(\Request::all());  
    return [
        'main_img' => 'image|mimes:png,jpg,jpeg',
    ];
}

what is the issue? i know the enctype is a must when submit a file. I used it in Laravel 5.0 and everything was ok why ij Laravel 5.1 did not work.

1 Answer 1

0

When using laravel 5.1, you should use:

dd(\Request::all());

Or getting the file:

dd(\Request::file('main_img));

Getting specific input:

dd(\Request::input('example_input_field'));

Code should look like something like this:

    {!! Form::open(array(
            'url'   => url('upload'),
            'method'=> 'POST',
            'files' => true)) 
    !!}

    {!! Form::file('file', array('type'=>'file')) !!}

    {!! Form::close() !!}

Caution: This example form uses: "illuminate/html": "~5.0", package

Sign up to request clarification or add additional context in comments.

3 Comments

the same when put it in rule function in request the array is empty public function rules() { dd(\Request::all());
the issue in image size: 4M when upload image less than 4M the validation success. but i see in php.ini upload_max_filesize = 64M what is the issue.
Are you using WAMP? If so, you also have to change the php.ini file located in : C:\wamp\bin\php\php5.X.X (where x is your php version)

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.