提问者:小点点

项目上载到laravel中的cpanel时未显示图像


我从我的实时网站上传的任何图像都不会显示...但是是工作罚款localhost我也做了php工匠存储:链接,但结果仍然是一样的。图像保存在公共文件夹中

....

我用这个逻辑保存图像

...

公共函数保存文件(请求$请求){

    $uploadPath = public_path(env('UPLOAD_PATH'));
    $thumbPath = public_path(env('UPLOAD_PATH').'/thumb');
    if (! file_exists($uploadPath)) {
        mkdir($uploadPath, 0775);
        mkdir($thumbPath, 0775);
    }

    $finalRequest = $request;

    foreach ($request->all() as $key => $value) {
        if ($request->hasFile($key)) {
            if ($request->has($key . '_max_width') && $request->has($key . '_max_height')) {
                // Check file width
                $filename = time() . '-' . $request->file($key)->getClientOriginalName();
                $file     = $request->file($key);
                $image    = Image::make($file);
                if (! file_exists($thumbPath)) {
                    mkdir($thumbPath, 0775, true);
                }
                Image::make($file)->resize(50, 50)->save($thumbPath . '/' . $filename);
                $width  = $image->width();
                $height = $image->height();
                if ($width > $request->{$key . '_max_width'} && $height > $request->{$key . '_max_height'}) {
                    $image->resize($request->{$key . '_max_width'}, $request->{$key . '_max_height'});
                } elseif ($width > $request->{$key . '_max_width'}) {
                    $image->resize($request->{$key . '_max_width'}, null, function ($constraint) {
                        $constraint->aspectRatio();
                    });
                } elseif ($height > $request->{$key . '_max_height'}) {
                    $image->resize(null, $request->{$key . '_max_height'}, function ($constraint) {
                        $constraint->aspectRatio();
                    });
                }
                $image->save($uploadPath . '/' . $filename);
                $finalRequest = new Request(array_merge($finalRequest->all(), [$key => $filename]));
            } else {
                $filename = time() . '-' . $request->file($key)->getClientOriginalName();
                $request->file($key)->move($uploadPath, $filename);
                $finalRequest = new Request(array_merge($finalRequest->all(), [$key => $filename]));
            }
        }
    }

    return $finalRequest;
}

...

...

我的配置/filesystem.php

...

“磁盘”=

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

    'uploads' => [
        'driver' => 'local',
        'root' => public_path('uploads'),
    ],

    'uploads_test' => [
        'driver' => 'local',
        'root' => public_path('uploads/test')
    ],

],

用这个来展示我的照片

<img src="{{ asset(env('UPLOAD_PATH').'/' . $room->display_image) }}"/>

共1个答案

匿名用户

我认为这是因为在本地,公用文件夹与项目的其他文件夹位于同一目录中(应用程序引导配置-…)但在共享主机中,这些项目文件夹不靠近公用文件夹(例如,公用html)

您应该在索引中设置公共路径。公开的php

类似下面的代码:

$app->bind('path.public', function() {
    return __DIR__;
});