Example #1
0
         } else {
             $errors['profile_picture'] = $upload_errors[$_FILES['profile_picture']['error']];
         }
     }
 }
 if (empty($errors)) {
     $user = new User();
     $mail_id = $_POST['mail_id'];
     $user->mail_id = $database->escape_value($mail_id);
     $first_name = $_POST['first_name'];
     $user->first_name = $database->escape_value($first_name);
     $last_name = $_POST['last_name'];
     $user->last_name = $database->escape_value($last_name);
     $password = $_POST['password'];
     $password = $database->escape_value($password);
     $hashed_password = User::generate_hash($password);
     $user->password = $hashed_password;
     $timestamp = strftime("%Y-%m-%d-%H-%M-%S", time());
     $target_path = "images/" . basename($timestamp) . basename($mail_id) . basename(substr($_FILES['profile_picture']['name'], -10, 10));
     if ($_FILES['profile_picture']['size']) {
         if (file_exists($target_path)) {
             $errors[] = "The filename already exists.";
         }
         if (move_uploaded_file($_FILES['profile_picture']['tmp_name'], $target_path)) {
             $user->profile_picture = $database->escape_value($target_path);
         } else {
             $errors['upload_error'] = "The profile picture upload failed, possibly due to incorrect permission on the target folder.";
         }
     } else {
         $user->profile_picture = null;
     }