Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'connect.php';
- if((!isset($_SESSION['user']) OR trim( $_SESSION['user'] ) == "") ) {
- header('Location: login.php');
- exit;
- }
- else{
- $username = $_SESSION['user'];
- if(isset($_POST['submit'])) {
- $query = "UPDATE users
- SET image=:image
- WHERE username = '$username'";
- $stmt = $pdo->prepare($query);
- $image = !empty($_FILES["image"]["name"])
- ? sha1_file($_FILES['image']['tmp_name']) . "-" . basename($_FILES["image"]["name"])
- : "";
- $image = htmlspecialchars(strip_tags($image));
- $stmt->bindParam(':image', $image);
- if ($image) {
- // sha1_file() function is used to make a unique file name
- $target_directory = "uploads/";
- $target_file = $target_directory . $image;
- $file_type = pathinfo($target_file, PATHINFO_EXTENSION);
- // error message is empty
- $file_upload_error_messages = "";
- $check = getimagesize($_FILES["image"]["tmp_name"]);
- if ($check !== false) {
- } else {
- $file_upload_error_messages .= "<div>Submitted file is not an image.</div>";
- }
- $allowed_file_types = array("jpg", "jpeg", "png");
- if (!in_array($file_type, $allowed_file_types)) {
- $file_upload_error_messages .= "<div>Only JPG, JPEG, PNG files are allowed.</div>";
- }
- if (file_exists($target_file)) {
- $file_upload_error_messages .= "<div>Image already exists. Try to change file name.</div>";
- }
- if ($_FILES['image']['size'] > (2048000)) {
- $file_upload_error_messages .= "<div>Image must be less than 2 MB in size.</div>";
- }
- if (!is_dir($target_directory)) {
- mkdir($target_directory, 0777, true);
- }
- if (empty($file_upload_error_messages)) {
- // it means there are no errors, so try to upload the file
- if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
- // it means photo was uploaded
- } else {
- echo "<div class='alert alert-danger'>";
- echo "<div>Unable to upload photo.</div>";
- echo "<div>Update the record to upload photo.</div>";
- echo "</div>";
- }
- } // if $file_upload_error_messages is NOT empty
- else {
- // it means there are some errors, so show them to user
- echo "<div class='alert alert-danger'>";
- echo "<div>{$file_upload_error_messages}</div>";
- echo "<div>Update the record to upload photo.</div>";
- echo "</div>";
- }
- $stmt->execute();
- //header("Refresh:1");
- }
- }
- else{
- $avatarQuery = "SELECT id, username, image FROM users WHERE username = '$username'";
- $avatarStmt = $pdo->prepare( $avatarQuery );
- //$stmt->bindParam(1, $id);
- $avatarStmt->execute();
- // store retrieved row to a variable
- $row = $avatarStmt->fetch(PDO::FETCH_ASSOC);
- $avatar = htmlspecialchars($row['image'], ENT_QUOTES);
- }
- }?>
- <!doctype html>
- <html lang="en">
- <head>
- <link rel="shortcut icon" href="images/logoNew_bubbles.png"/>
- <link type="text/css" rel="stylesheet" media="screen"
- href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
- integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- <link href="css/styles.css" rel="stylesheet">
- <link rel="stylesheet" href="css/test.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
- integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <meta name="description" content="">
- <meta name="author" content="">
- <title>User Dashboard</title>
- </head>
- <body class="text-center" style="background-color:#eee">
- <header class="fixed-top">
- <?php include_once "php_includes/header.php"; ?>
- </header>
- <div class="container" style="margin-top: 100px; margin-bottom: 150px;">
- <div class="col-sm-1"></div>
- <div class="col-sm-10" style="text-align:center; margin-top: 50px">
- <div class="row">
- <div class="col-lg-12">
- <h2>Profile</h2>
- <p><?php echo $avatar ? "<img src='uploads/{$avatar}' style='width:300px;' />" : "<img src='images/avatar.jpg' style='width:300px;';>" ?></p>
- </div>
- </div>
- <div>
- <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
- <div class="row justify-content-md-center mb-1">
- <div class="col-md-3">tr</div>
- <div class=" col-md-auto">
- <input class="form-control-file" type="file" name="image" id="image">
- </div>
- <div class="col-md-1">ty</div>
- </div>
- <input class="btn btn-success mb-1" type="submit" value="Upload Image" name="submit">
- <div class="border rounded my-5 py-3 ">
- Lorem Ipsum is simply dummy text of the printing and typesetting industry.
- Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when
- an unknown printer took a galley of type and scrambled it to make a type specimen book.
- It has survived not only five centuries,
- </div>
- <div class="form-group">
- <label> Info about me </label>
- <textarea id="infoAboutMe" name="infoAboutMe" class="form-control" rows="5"></textarea>
- </div>
- </form>
- </div>
- <div>
- <h2 class="welcome mt-5 ">My Favorite Beers</h2>
- </div>
- <div class="row justify-content-md-center my-3 py-3">
- <div class="polaroid rounded col-sm-4">
- <div class="col-md">
- <img src="images/heineken.png">
- <p>Beer 1</p>
- </div>
- </div>
- <div class="polaroid rounded col-sm-4">
- <div class="col-md">
- <img src="images/heineken.png">
- <p>Beer 2</p>
- </div>
- </div>
- <div class="polaroid rounded col-sm-4 ">
- <div class="col-md">
- <img src="images/heineken.png">
- <p>Beer 3</p>
- </div>
- </div>
- </div>
- <div>
- <div class="row my-3">
- <button class="btn btn-warning shanoClass">Save Changes</button>
- </div>
- </div>
- <div class="justify-content-md-center row my-3">
- <button class="btn btn-warning mx-3">Change info</button>
- <button class="btn btn-warning mx-3">My orders</button>
- </div>
- <div class="justify-content-md-center row my-3">
- <button class="btn btn-warning mx-3">My wallet</button>
- <button class="btn btn-warning mx-3">Basket</button>
- </div>
- </div>
- <div class="col-sm-1"></div>
- </div>
- <footer class="container fixed-bottom">
- <?php include_once "php_includes/footer.php"; ?>
- </footer>
- <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
- <script>
- $(document).ready(function () {
- $("#profile").addClass('text_shadow');
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment