Nileshsinh Rathod
Nileshsinh Rathod

Reputation: 968

Laravel image not shown on server and working fine on my local machine

On my local machine project working file but when i uploaded on my server then all images are not shown, and NotFoundHttpException error when i hit full image path to browser.

mypath to project is as

/public_html/offlinemall/public 

And Below is my 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_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],
    'featured' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

],

And how i get image

<img style="height: 480px" src="storage/{{ $ad->avatar }}">

In inspect i get full path but when i hit url then i get NotFoundHttpException error.

http://compare.theofflinemall.com/storage/featured_image/qzHWpQeSfKjZ6DOS59ROyYboJ1GCvVi6NNVfLtVV.jpeg

Upvotes: 1

Views: 11695

Answers (5)

Nasir
Nasir

Reputation: 1

If you remove storage/uploads directory and recreate it using php artisan storage:link, the issues will be resolved.

Upvotes: 0

Dickson Martey
Dickson Martey

Reputation: 1

if you have done all that try this:

Check your .env file and APP_URL value: it should be https://[yourwebsite.com] - some people forget to change it from the default localhost or provide incorrect URL with an extra folder/subdomain

Upvotes: 0

Ziaur Rahman
Ziaur Rahman

Reputation: 1188

Basically it has symbolic issue. Probably you have used storage directory to store images. If you use it you need to create a symbolic link by php artisan storage:link. It creates a symbolic directory into your local project's public directory with storage name. When you upload the project on server the symbolic directory won't upload with your project. So, reasonably the browser won't get the path and doesn't show the image. In these perspective there are many solutions:

Solution 1: ssh key access, if you have your server's ssh key access, login into your server using ssh key, go to your project directory and run the command php artisan storage:link it will create the symbolic directory to your project.

Solution 2: By creating cron job on the server.

Solution 3: By executing php script to create symbolic link. Please go through this link cron job and php file execution.

Solution 4: By changing the root directory of image path in config/filesystem.php. please go through this url laracast.com

Upvotes: 4

alexeis
alexeis

Reputation: 34

Your server can't locate storage as path because it uses public_path run

php artisan storage:link

It should work. Also, try to use

{{ asset('storage/'.$ad->avatar) }}

Upvotes: 2

M_Idrees
M_Idrees

Reputation: 2172

You can change image tag to:

  1. <img src={{ asset('storage/'.$ad->avatar) }} />
  2. <img src="storage/app/public/{{$ad->avatar) }}" />
  3. <img src="<?php echo asset("storage/app/public/$ad->avatar")?>"></img>

Upvotes: 0

Related Questions