简体   繁体   中英

Laravel not showing image from url

I have issue with access some of images from my Storage on shared hosting.

For example: <my_domain>/storage/captcha/baa5271fe19d696d6e83388a5c22f13c40ecc470.jpg display html page but <my_domain>/storage/images/slider1.jpg display image.

Intervention\\Image\\Facades\\Image is used to generate captcha image.

filesystems.php config to compare:

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

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

Privileges for Storage was set as 777. storage:link was also set.

.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

It's happening only on shared hosting so I guess it's something with .htaccess.

解决方案是从 public 中删除 storage 目录并再次执行 storage:link 命令。

as you are using shared hosting use public path insted of storage path

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

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

and only gives folder name
it's working for me you can try it.

If you are using shared hosting then use public path

'images' => [
            'driver' => 'local',
            'root' =>  public_path() . '/Any folder name of image',
            'url' => env('APP_URL').'/storage/images/',
            'visibility' => 'public',
        ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM