查看具有文件哈希名称Laravel

时间:2018-12-19 06:46:37

标签: php laravel image

我想从“文件哈希”列获取图像(图像名称)。因此,URL不直接显示图像名称。这是我的控制器:

public function viewImageD($filehash){
       $filename = DB::table('formd_image_detail')
        ->select('form_image')
        ->where('filehash', $filehash)
        ->get();
        $storagePath = (env('FORMD_IMAGE_URL') .$filename['form_image']);
        $result = Image::make($storagePath)->response();
        return $result;
}

此代码运行时出现错误。

[2018-12-19 06:20:59] local.INFO: [{"form_image":"imagedavid.png"}]  
[2018-12-19 06:21:00] local.ERROR: Undefined index: form_image 

控制器的正确代码如何?感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您应该尝试以下操作:

请在env文件中传递config/app.php变量,例如:

config / app.php

'storage_path' => env('FORMD_IMAGE_URL', 'your path'),

您的控制器 使用Config;

public function viewImageD($filehash){
       $filename = DB::table('formd_image_detail')
        ->select('form_image')
        ->where('filehash', $filehash)
        ->get();
        $storagePath = (Config::get('app.storage_path') .$filename['form_image']);
        $result = Image::make($storagePath)->response();
        return $result;
}