elo

Images uploaded in storage not accessible

Posted 1 week ago by elo

In a laravel 5.6 project, I created a symbolic link using php artisan symboli:link cammand which then created a storage directory in my public folder on my development server. Everything seems to work fine on dev server but after deploying on shared hosting, image upload works fine and I can see the image in appname/storage/app/public/images/photos but the file is not in public_html/storage/images/photos.

When I copied an uploaded file from appname/storage/app/public/images/photos to public_html/storage/images/photos, I was able to display the picture on the site as I wanted.

How can I fix this issue? This is how I am uploading the images

public function store(Request $request)
{
    $this->validate(request(), [
        'photo' => 'required|max:4000|mimes:jpeg'
    ]);

    /**
        * Retrieve uploaded photo
        * Define storage path
        * Get original file extension
        * Define filename to store photo & upload file
        */
    $file = $request->file('photo');
    $destinationPath = 'public/images/photos/';
    $filename = 'rayda_concept_photos_'.rand(1, 1000).'.'.$file->extension();

    if (Storage::putFileAs($destinationPath, $file, $filename)) {
        $photo = Photo::create([
            'photo' => $filename
        ]);

        Session::flash('success', 'You have successfully uploaded a photo.');

        return back();
    }

}

filesystem.config file looks like this (no change made)

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

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

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

html used for displaying the image

<div class="card">
         <img src="{{ URL::asset('storage/images/photos/'.$photo->photo) }}" alt="{{$photo->photo}}" class="card-img-top img-fluid">
</div>

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.