Manchesteriyah
Manchesteriyah

Reputation: 111

Laravel 5.8 - Uploaded Image not showing on Shared Hosting but Shows on Local Server

I've deployed my laravel project on my Shared Host, and try some my project features one of them is uploading an image. The image successfully uploaded into my Storage Folder, but when I try to view the image, my console give me 404 on that uploaded image URL like this URL :

http://member.gunabraham.com/storage/site/images/Site_Logo_1561217248.png

But in my local server, the uploaded image shows correctly on this URL :

http://localhost:8000/storage/site/images/Site_Logo_1561217645.png

This is my config/filesystems.php :

'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'),
    ],

],

And my HTML file :

<a href="{{url('/home')}}" class="brand-logo amber-text center"><img src="{{asset('storage/site/images/'.$siteinfo->site_logo)}}" alt="" width="70" style="margin-top:15px;margin-bottom:15px;">

So what should I do on my laravel project which is deployed on Shared Hosting? Thanks for attention.

Upvotes: 0

Views: 3704

Answers (3)

Manchesteriyah
Manchesteriyah

Reputation: 111

Solved by change my image source in HTML file from :

storage/site/images/

to :

storage/app/public/site/images/

Is this right choice? Or there're another solution to solve this problem?

Upvotes: 2

Saurav
Saurav

Reputation: 363

Your files are being uploaded in the storage path and not the public path. You have mainly two options here: 1. Change your file-system to public path.

 In your /config/filesystems.php
  'public' => [
  'driver' => 'local',
  'root' => public_path('app/public/'),
  'url' => env('APP_URL').'/storage',
  'visibility' => 'public',
],
  1. Create a symlink and point the storage files via public folder. To do this you can run php artisan storage:link in your server console. If you don't have console access to server you can do this using a cron job.

Option 1 is better if you are using shared hosting with no console access.

Upvotes: 0

Developer
Developer

Reputation: 474

You want to try link storage folder. if /public/storage folder is already exists first go to public folder and delete exising storage folder then run this command Are you tryed ? try this command php artisan storage:link if you don't have command pannel in shere hosting please create one route for run a comand

Route::get('/command',function(){ Artisan::call('storage:link'); });

Upvotes: 0

Related Questions