Advertisement
lowheartrate

asdasdasd s

Dec 1st, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. // require config.php to get maximum file size --> $maximum_avatar_file_size = '125000';
  2.           //                    to get avatars directory --> $avatars_directory = 'includes/uploads/avatars';
  3.           require 'core/config.php';
  4.  
  5.           // need for file upload query & query to insert fields into database..
  6.           $activation_id = uniqid(true);
  7.  
  8.           // file upload stuff... ONLY NEEDED FOR TESTING PURPOSES!
  9.           // var_dump($_FILES);
  10.  
  11.           // move uploaded file to directory (includes/uploads/avatar)
  12.           $upload_directory = $avatars_directory;
  13.           // sets $image & gets image type, name, tmp_name
  14.           $image = $_FILES['avatar'];
  15.           $image_name = $_FILES['avatar']['name'];
  16.           $image_tmp_name = $_FILES['avatar']['tmp_name'];
  17.           $image_size = $_FILES['avatar']['size'];
  18.           $image_type = $_FILES['avatar']['type'];
  19.  
  20.           // set file name (make it unique)
  21.           $file_name = $activation_id . $image_name;
  22.  
  23.           // finds extension of file uploaded...
  24.           $image_extension = strtolower(pathinfo($_FILES['avatar']['name'],PATHINFO_EXTENSION));
  25.           // allowed extensions of file uploaded...
  26.           $valid_image_extensions = array('jpeg', 'jpg', 'png', 'gif');
  27.  
  28.           // if image extension is a valid image extension...
  29.           if (in_array($image_extension, $valid_image_extensions)) {
  30.             if ($image_size > $maximum_avatar_file_size) {
  31.               echo '<p class="error">error; file size is too large! Maximum file size is ' .$maximum_avatar_file_size. ' bytes. <a href="action.php?action=register_account">Retry Registration</a></p>';
  32.               exit();
  33.             } else {
  34.               // move the file to desired directory ($upload_directory)
  35.               move_uploaded_file($image_tmp_name, "$upload_directory/$file_name");
  36.             }
  37.           }
  38.  
  39.  
  40.           // query to insert fields into database...
  41.           //$activation_id = uniqid(true);
  42.           $query = dbConnect()->prepare("INSERT INTO users (username, password, email, activated, activation_id, avatar) VALUES (:username, :password, :email, :activated, :activation_id, :avatar)");
  43.           $query->bindParam(':username', $username);
  44.           $query->bindParam(':email', $email);
  45.           $query->bindParam(':password', $hash);
  46.           $query->bindValue(':activated', "0");
  47.           $query->bindValue(':activation_id', $activation_id);
  48.           $query->bindValue(':avatar', $file_name);
  49.           $query->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement