我有一个api将图像存储到文件夹和db,当我尝试使用Postman测试api时,它总是返回“无法打开流:文件中没有此类文件或目录”,请帮帮我。谢谢。
控制器:
$path = base_path('storage/app/public/profile/');
$base = $request->picture;
$binary = base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
$f = finfo_open();
$mime_type = finfo_buffer($f, $binary, FILEINFO_MIME_TYPE);
$mime_type = str_ireplace('image/', '', $mime_type);
$filename = md5(\Carbon\Carbon::now()) . '.' . $mime_type;
$file = fopen($path . $filename, 'wb'); "this line throws that error"
if (fwrite($file, $binary)) {
$user = User::find(auth()->id());
$user->profile_image = 'profile/' . $filename;
$user->save();
return response()->json(array('result' => "yes"));
} else {
return response()->json(array('result' => "no"));
}
fclose($file);