<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/bootstrap.php'; $file = $_FILES['file']; $title = $_POST['title']; $validator = new \MyClasses\Validation\Validator(); $rules = ['title' => ['not_empty'], 'file' => ['image_upload_file']]; $data = ['title' => $title, 'file' => $file]; $validator->validate($rules, $data); if ($validator->getError('upload_image')) { redirect_with_message('/uploads/index.php', $validator->getError('upload_image')); } $validator->redirectIfFailed('/uploads/index.php'); $upload_id = \MyClasses\Models\Upload::createAndSave($file['tmp_name'], $file['name'], $file['type'], $file['size'], $title); redirect_with_message('/uploads/index.php', "{$file['name']} was uploaded!");
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/bootstrap.php'; $rules = ['email' => ["email"], 'password' => ["not_empty"]]; $validator = new \MyClasses\Validation\Validator(); $validator->validate($rules, $_POST); $validator->redirectWithErrorsIfFailed('/users/login.php'); $user = \MyClasses\Models\User::getOneBy('email', $_POST['email']); $hashed = $user['encrypted_password']; $password_is_correct = password_verify($_POST['password'], $hashed); if ($password_is_correct) { \MyClasses\Auth\AuthMaster::logUserInUsingId($user['id']); redirect_user('/users/index.php', "Log in success. Congratulations, {$user['first_name']}!"); } else { redirect_user('/users/login.php', "Wrong password! Try again..."); }