Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // require config.php to get maximum file size --> $maximum_avatar_file_size = '125000';
- // to get avatars directory --> $avatars_directory = 'includes/uploads/avatars';
- require 'core/config.php';
- // need for file upload query & query to insert fields into database..
- $activation_id = uniqid(true);
- // file upload stuff... ONLY NEEDED FOR TESTING PURPOSES!
- // var_dump($_FILES);
- // move uploaded file to directory (includes/uploads/avatar)
- $upload_directory = $avatars_directory;
- // sets $image & gets image type, name, tmp_name
- $image = $_FILES['avatar'];
- $image_name = $_FILES['avatar']['name'];
- $image_tmp_name = $_FILES['avatar']['tmp_name'];
- $image_size = $_FILES['avatar']['size'];
- $image_type = $_FILES['avatar']['type'];
- // set file name (make it unique)
- $file_name = $activation_id . $image_name;
- // finds extension of file uploaded...
- $image_extension = strtolower(pathinfo($_FILES['avatar']['name'],PATHINFO_EXTENSION));
- // allowed extensions of file uploaded...
- $valid_image_extensions = array('jpeg', 'jpg', 'png', 'gif');
- // if image extension is a valid image extension...
- if (in_array($image_extension, $valid_image_extensions)) {
- if ($image_size > $maximum_avatar_file_size) {
- 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>';
- exit();
- } else {
- // move the file to desired directory ($upload_directory)
- move_uploaded_file($image_tmp_name, "$upload_directory/$file_name");
- }
- }
- // query to insert fields into database...
- //$activation_id = uniqid(true);
- $query = dbConnect()->prepare("INSERT INTO users (username, password, email, activated, activation_id, avatar) VALUES (:username, :password, :email, :activated, :activation_id, :avatar)");
- $query->bindParam(':username', $username);
- $query->bindParam(':email', $email);
- $query->bindParam(':password', $hash);
- $query->bindValue(':activated', "0");
- $query->bindValue(':activation_id', $activation_id);
- $query->bindValue(':avatar', $file_name);
- $query->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement