InvalidArgumentException获取图像时格式错误的UTF-8字符

时间:2017-07-03 12:23:32

标签: laravel lumen

当我尝试获取图像时显示错误:

  

InvalidArgumentException可能是格式错误的UTF-8字符   编码错误

这是我的代码:

public function getImage($id){
    $users = AdminLogin::find($id);
    $path = "uploads/images/{$users->image_file}";

    if(!File::exists($path)) {
        return response()->json(['message' => 'Image not found.'], 404);
    }       
    $file = File::get($path);       
    return response()->json($file);     
}

1 个答案:

答案 0 :(得分:0)

public function getImage($id){
    $users = AdminLogin::find($id);
    $path = "uploads/images/{$users->image_file}";

    if(!File::exists($path)) {
        return response()->json(['message' => 'Image not found.'], 404);
    }       
    $file = File::get($path);       
   return response($file, 200)->header('Content-Type', 'image/jpeg');
}