我尝试在浏览器中传输pdf,但它仍然告诉我我传递一个字符串作为参数。
public function cv($id){
$user = new user;
$cv = $user->where('id', $id)->firstOrfail()->Publicprofile->cv_path;
return response()->file(Storage::get($cv));
}
当我尝试传递文件名和路径时,它告诉我文件不存在
return response()->file($cv);
这是我的文件系统配置设置
'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_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
以下是 $ cv 变量返回的值
"public/cv/61520610986.pdf"
答案 0 :(得分:0)
解决方案要求我使用
提供绝对路径Public_path() method
最终做到了这一点:
public function streamCV($id){
$user = new user;
$cv = $user->where('id', $id)->firstOrfail()->Publicprofile->cv_path;
$cv ="storage". ltrim($cv, 'public');
return response()->file(public_path($cv));
}