当我尝试获取图像时显示错误:
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);
}
答案 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');
}