0
votes

I have a problem with my laravel project. I did a system where the client have to upload products with a pic. But when I upload the project to the online host, the upload of image not work, and i cant find where is the problem.

Advertisement: I have the Laravel folder out of public_html, and i don't using the principal folder (public_html), but i'm using another domain in the server, so the config of path ta you see it have not "public_html"

The code:

Controller

public function store(Request $request)
    {
        $newProduct = new App\Product;

        $newProduct -> name = $request -> name;
        $newProduct -> description = $request -> description;
        $newProduct -> price = $request -> price;

        if ( $request -> hasFile('photo') ) {
            $file = $request -> file("photo");
            $fileUpload = Storage::disk('public') -> put('img/products', $file);
            $newProduct -> photo = $fileUpload;
        }

        $newProduct -> save();

        return back() -> with('status', 'Ok.');
    }

filesystem:

'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

and the config path

public function register()
    {
        $this->app->bind('path.public',function(){
            return'/home1/client/domain.com/menu';
        });
    }

Important: When i save the register, it work, I can see the filename in DB, but not save the file in folder.

1

1 Answers

0
votes

Thanks, but putFile not worked.

Finally i could fix the error. I don't know why it was creating a folder and saving the files in Laravel folder. So, i replaced manually "public_path" by the route, just a string. And now it's saving in the correct folder.