Laravel不显示来自URL的图像

时间:2020-02-07 12:50:51

标签: php laravel storage

我在共享主机上从存储访问某些图像时遇到问题。

例如:<my_domain>/storage/captcha/baa5271fe19d696d6e83388a5c22f13c40ecc470.jpg显示html页面,而<my_domain>/storage/images/slider1.jpg显示图像。

Intervention\Image\Facades\Image用于生成验证码图像。

filesystems.php配置进行比较:

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

存储特权设置为777。还设置了 storage:link

.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>

仅在共享主机上发生,因此我想它与.htaccess有关。

3 个答案:

答案 0 :(得分:0)

解决方案是从公共目录删除存储目录,然后再次执行storage:link命令。

答案 1 :(得分:-1)

在使用共享主机时,请使用由public路径插入的storage路径

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

,仅提供文件夹名称
它对我有用,您可以尝试一下。

答案 2 :(得分:-2)

如果您使用共享主机,则使用公共路径

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