How to change the path to save an image with Laravel

0

Thank you to hire a hosting that does not let me access beyond the public_html. I must put the whole project there, using public_html as root. Then separate in a folder called laravel, the whole project and leave loose in public_html everything that belonged to public

Changing the index a bit like this

require __DIR__.'/laravel/bootstrap/autoload.php';

$app = require_once __DIR__.'/laravel/bootstrap/app.php';

I started walking, I had a privilege problem, so at first the photos were not visible, the issue is that when uploading an image from my site, I created the public / img inside laravel and uploads the image correctly, but it is hosted there and not in the img inside public_html

A fragment of code of how I show an image

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

        $evento->imagen = $nombre;

    }

I have to get it to stay correctly from my root, which in my case is public_html / img /...

modifying the public_path () in app / Providers / AppServiceProvider in such a way that the public lowers a level to the public_html would be the solution

public function register()
{

    $this->app->bind('path.public', function() {
        return base_path().'/public_html'; // como moficar esta linea para que me imprima correctamente
    });
}

I leave my site for easier to verify the problem: emap.com.ar

    
asked by Cidius 15.10.2016 в 05:44
source

2 answers

0
$app = require_once __DIR__.'/../bootstrap/app.php';

// set the public path to this directory

$app->bind('path.public', function() {
    return __DIR__;
});

Try adding this snippet of code that you should change in the index.php

file

Source: link

    
answered by 16.10.2016 / 18:47
source
-1

I can not answer your message directly. Checking your code, the photos give me error 403, check the permissions of the photos are 644 or 755 or 777.

    
answered by 15.10.2016 в 05:52