mornenel79's avatar

Upload of image to public/img fails on server

I set this up as follows.

It works perfectly fine on a localhost setup, but doing it through Client Server, it fails to upload the image or logo.

What am I missing here?

UploadFileController.php

public function uploadLogo(Request $request) {

    $user = Auth::user();
    if ($user) {
       
        $file = $request->file;
        $publicPath = public_path();
        $path = $publicPath.'\img\logo.png';

        if (File::exists($path)) {
            File::delete($path);                
        }

		$path = $request->file->storeAs('img', 'logo.png', 'logo');
        return 'saved';
    }

}

filesystems.php

	'logo' => [
		'driver' => 'local',
		'root'   => public_path(),
		'url' => env('APP_URL').'/public',
		'visibility' => 'public',
	],
0 likes
5 replies
tinkerbell's avatar
Level 1

in laravel you have to create link to your storage folder in public folder using command , then you can see images,

php artisan storage:link 
mornenel79's avatar

Does this apply even if I save to public/img?

1 like
tinkerbell's avatar

Yes, it's the same without using the command I meantioned your images will not be visible

fatenfalfoul's avatar

Just try to inverse the \ by / on your code like changing $path = $publicPath.'\img\logo.png'; $path = $publicPath.'/img/logo.png';

Please or to participate in this conversation.