How to fix error when loading image in laravel?

0

I have uploaded an image in laravel, however I am receiving the following error:

LogicException in MimeTypeGuesser.php line 135: Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)

As I can solve it, I am using the command line to run my application ( php artisan serve --port=8081 )

This is the code I use

public function store (ArticuloFormRequest $request)
    {
        $articulo=new Articulo;
        $articulo->idcategoria=$request->get('idcategoria');
        $articulo->codigo=$request->get('codigo');
        $articulo->nombre=$request->get('nombre');
        $articulo->stock=$request->get('stock');
        $articulo->descripcion=$request->get('descripcion');
        $articulo->estado='Activo';

        if (Input::hasFile('imagen')){
            $file=Input::file('imagen');
            $file->move(public_path().'/imagenes/articulos/',$file->getClientOriginalName());
            $articulo->imagen=$file->getClientOriginalName();
        }
        $articulo->save();
        return Redirect::to('almacen/articulo');
}
    
asked by lucho 10.04.2017 в 18:31
source

1 answer

2

I had the same problem, I chose to use php methods to log files to the server. I hope it helps you.

public function upload_files(){
    //get the file
    $path  = Input::get('path'); //AQUÍ PUEDES DEFINIR EL PATH DONDE SE VA A GUARDAR LA IMÁGEN ESTE LO OBTENGO DESDE EL FRONT PORQUE EL USUARIO SELECCIONA A DONDE SE VA A GUARDAR

    $array_files = array();

    $count = 0;
    $status = true;

    foreach ($_FILES['file']['name'] as $filename)
    {
        $file = basename($filename);
        $file = 'public/' . $path . '/' . $file;
        $file_extension = pathinfo($file, PATHINFO_EXTENSION);
        $file_size = $_FILES["file"]["size"];

        //VERIFICO SI EXISTE
        if(file_exists($file)){
            $status = false;
        }

        //VERIFICO LA EXTENSION
        if($file_extension != "jpg" && $file_extension != "png" && $file_extension != "jpeg" && $file_extension != "gif" ) {
            $status = false;
        }

        if($status){

            //VERIFICAMOS SI SE GUARDA LA IMAGEN
            if( move_uploaded_file($_FILES["file"]["tmp_name"][$count], $file ) ){
                //AQUÍ PUEDES GUARDAR DATOS EN LA BD O HACER OTRO PROCESO
            }
        }else{
            //ERROR
        }

        $count ++;
    }



    $response = 'DATOS GUARDADOS';

    return $response;

}

    
answered by 10.04.2017 в 21:29