problems to save a file in the public_html of the hosting in Laravel

-2

The file (in this case an image) does not upload to the hosting public. Unusually something that started to happen to me today. Without reason. I did not make any changes to the controller. And localhost is perfect

Restart the hosting to 0 and return to move all folders and remains the same.

I leave the controller, where I bring a request with the file

public function store(ArticuloRequest $request)
{
    $articulo = new Articulo($request->all());
    $articulo->usuario_id = \Auth::user()->id;
    $articulo->save();

    $articulo->tags()->sync($request->tags);


    if($request->file('imagen'))
    {
        //Manipulacion de imagenes
        $file= $request->file('imagen');
        $nombre= 'emap_'.time().'.'.$file->getClientOriginalExtension();
        $path = public_path().'/img/articulos';
        $file->move($path,$nombre);

        $img = new Imagen();
        $img->nombre = $nombre;
        $img->articulo()->associate($articulo);
        $img->save();
        dd($path);         
    }


    flash("Se ha creado el articulo ".$articulo->titulo." de forma exitosa!", 'success')->important();

    return redirect()->route('articulos.index');

}

the dd ($ path) returns me

"/home/u923520231/public/img/articulos"

The data base is u923520231_emap. I am using a shared hosting (hostinger)

    
asked by Cidius 01.10.2016 в 05:27
source

1 answer

1

I found the Problem. By default the folder in laravel is public. But it is not enough to change the name (as it is not worth changing to public the public_html of the hosting)

What we should do is change the name to the project folder (to which the hosting offers us) and then register the change within the register method of the AppServiceProvider class located at: app / Providers / AppServiceProvider

public function register()
{

    $this->app->bind('path.public', function() {
        return base_path().'/public_html';
    });
}
    
answered by 03.10.2016 / 01:34
source