error !== UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($id_document->error)); if($photo->error !== UPLOAD_ERR_OK) $form_exception->addError(HTTP::getUploadErrorString($photo->error)); $size = @getimagesize($id_document->tmp_name); if(!$size) $form_exception->addError(__("The uploaded ID document is not an image.")); [$width, $height, $type] = $size; if($type !== IMAGETYPE_JPEG) $form_exception->addError(__("The uploaded ID document is not a JPEG.")); $size = @getimagesize($photo->tmp_name); if(!$size) $form_exception->addError(__("The uploaded photo is not an image.")); [$width, $height, $type] = $size; if($type !== IMAGETYPE_JPEG) $form_exception->addError(__("The uploaded photo is not a JPEG.")); if($form_exception->hasErrors()) throw $form_exception; $files = [ ["file" => $id_document, "name" => "ID document", "type" => UserFile::TYPE_ID], ["file" => $photo, "name" => "photo", "type" => UserFile::TYPE_PHOTO], ]; foreach($files as $file_info) { ["file" => $file, "name" => $name, "type" => $type] = $file_info; $output_image = Image::normalise($file->tmp_name); $user_file = new UserFile; $user_file->user_id = $user->id; $user_file->type = $type; $user_file->dts_uploaded = Util::getDateTime(); $success = $user_file->commit(); if(!$success) throw new Exception(sprintf(__("Failed to save the %s. Please try again later."), $name)); $output_path = $user->getDirectory() . "/" . $user_file->id . ".jpg"; $success = imagejpeg($output_image, $output_path, 60); imagedestroy($output_image); if(!$success) throw new Exception(__("Failed to save %s.", $name)); } $user->level = User::LEVEL_UNVERIFIED; $success = $user->commit(); // TODO: Send out pending verification email Core::addAlert("success", __("ID submitted successfully.")); HTTP::redirect("/account"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } View::includeOnce("header", compact("page_title")); View::include("submit_id"); View::includeOnce("footer");