Wednesday, April 12, 2017

Laravel Controller not receiving file from form

I have a form looking like this:

{!!Form::open(['route' => ['productos.update', ':PROD_ID'], 'method'=>'PUT', 'id'=> 'form-update', 'files'=>true]) !!}
{!!Form::hidden('name',null,['class'=>'form-control prod-update-text', 'id'=> 'form-update-name'])!!}
{!!Form::file('img')!!}
{!!Form::close() !!}

The problem is that when I post it via ajax to my controller, and ask for it using error_log in the controller:

public function update(Request $request, $id)
    {
        try{
            error_log($request->img);
            error_log(request()->img);
                      ...

It must show a temp image as following:

[Wed Apr 12 18:38:46 2017] C:\xampp\tmp\php93AE.tmp

But it doesn´t show that. It just print this:

[Wed Apr 12 19:43:52 2017]

It seems like if it didn't have nothing, It just works in other form I have to create a product, but in this form to update a product doesn't work. When I try to retrieve the file to update the product image from controller, it apparently clears all my post/get data if the file exceeds a limit.

Note I'm using 'files'=>true in the form as specify in the docs

Related Question suggest to modify the php.ini file, but I have modified it like this:

...
memory_limit=128M
...
post_max_size=20M
...
upload_max_filesize=19M
max_file_uploads=20
...

Even that, it doesn't work yet.

Can anyone help me?

Additional Info:

If it helps, I'm sending my data to the controller via ajax using this:

var form = $('#form-update');
var url = form.attr('action').replace(':PROD_ID', id); //I get the id previously
//Lo sig. se hace para obtener los datos del form para poder enviar la peticion con AJAX
var data = form.serialize();
//para enviar la peticion con AJAX:
$.post(url, data, function (result) {
    if(result.status === 'success'){
        ...
    }
});



via JON STIV

Advertisement