public function savePhoto() { $input = \Request::all(); $data = explode(',', $input['image_base64']); $filename = $input['filename']; $ext = pathinfo($filename, PATHINFO_EXTENSION); $ext_extra_data = parse_url($ext, PHP_URL_QUERY); $ext = str_replace("?" . $ext_extra_data, "", $ext); $filename = uniqid() . "." . $ext; $ifp = fopen($this->save_photo_path . "/" . $filename, "wb"); fwrite($ifp, base64_decode($data[1])); fclose($ifp); $type = exif_imagetype($this->save_photo_path . "/" . $filename); if (!in_array($type, $this->allow_image_types)) { return response(['error' => 'not_allowed'], 412); } // deactivate other photos $affected = UserPhoto::where('status', '=', 1)->where('user_id', \Auth::user()->id)->update(array('status' => 0)); $userPhoto = new UserPhoto(); $userPhoto->user_id = \Auth::user()->id; $userPhoto->filename = $filename; $userPhoto->save(); $userPhoto->path = url("/" . $this->save_photo_folder . "/" . $userPhoto->filename); return $userPhoto; }