upload a file in local laravel

1

I want to upload a file from a form in Laravel.

Input::file('imagen')->move('/public/imagenes/asdf',$producto->id.Input::file('imagen')->getClientOriginalName());

I tried this but it does not work, I get this error:

  

Call to a member function move () on null

    
asked by Doe 09.08.2017 в 08:57
source

2 answers

2

You are using Input when you have to refer to $request who is the one who has the temporary file.

Here is a small example of the Laravel Wiki:

link

In the example you are using Storage , but the move is worth it once you have the name of the variable within $request .

To not copy and paste, I leave the differences between Input and $request

link

    
answered by 09.08.2017 / 11:05
source
1

I've ever done it like that, I hope it works for you:

        $file = Input::file('file');

        $destinationPath = public_path(). '/img/';
        $filename = $file->getClientOriginalName();
        $file->move($destinationPath, $filename);
        $producto = new Producto();

        $producto->img_path = 'img/'.$filename;
        $producto->save();
    
answered by 11.08.2017 в 03:30