karlokokkak

Untitled

Mar 30th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.91 KB | None | 0 0
  1. <?php
  2. require_once 'connect.php';
  3. if((!isset($_SESSION['user']) OR trim( $_SESSION['user'] ) == "") ) {
  4.     header('Location: login.php');
  5.     exit;
  6. }
  7. else{
  8.  
  9.     $username = $_SESSION['user'];
  10.     if(isset($_POST['submit'])) {
  11.     $query = "UPDATE users
  12.            SET image=:image
  13.            WHERE username = '$username'";
  14.  
  15.     $stmt = $pdo->prepare($query);
  16.  
  17.     $image = !empty($_FILES["image"]["name"])
  18.         ? sha1_file($_FILES['image']['tmp_name']) . "-" . basename($_FILES["image"]["name"])
  19.         : "";
  20.     $image = htmlspecialchars(strip_tags($image));
  21.  
  22.     $stmt->bindParam(':image', $image);
  23.     if ($image) {
  24.  
  25.         // sha1_file() function is used to make a unique file name
  26.         $target_directory = "uploads/";
  27.         $target_file = $target_directory . $image;
  28.         $file_type = pathinfo($target_file, PATHINFO_EXTENSION);
  29.  
  30.         // error message is empty
  31.         $file_upload_error_messages = "";
  32.  
  33.         $check = getimagesize($_FILES["image"]["tmp_name"]);
  34.         if ($check !== false) {
  35.  
  36.         } else {
  37.             $file_upload_error_messages .= "<div>Submitted file is not an image.</div>";
  38.         }
  39.  
  40.         $allowed_file_types = array("jpg", "jpeg", "png");
  41.         if (!in_array($file_type, $allowed_file_types)) {
  42.             $file_upload_error_messages .= "<div>Only JPG, JPEG, PNG files are allowed.</div>";
  43.         }
  44.         if (file_exists($target_file)) {
  45.             $file_upload_error_messages .= "<div>Image already exists. Try to change file name.</div>";
  46.         }
  47.  
  48.         if ($_FILES['image']['size'] > (2048000)) {
  49.             $file_upload_error_messages .= "<div>Image must be less than 2 MB in size.</div>";
  50.         }
  51.  
  52.         if (!is_dir($target_directory)) {
  53.             mkdir($target_directory, 0777, true);
  54.         }
  55.  
  56.         if (empty($file_upload_error_messages)) {
  57.             // it means there are no errors, so try to upload the file
  58.             if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
  59.                 // it means photo was uploaded
  60.             } else {
  61.                 echo "<div class='alert alert-danger'>";
  62.                 echo "<div>Unable to upload photo.</div>";
  63.                 echo "<div>Update the record to upload photo.</div>";
  64.                 echo "</div>";
  65.             }
  66.         } // if $file_upload_error_messages is NOT empty
  67.         else {
  68.             // it means there are some errors, so show them to user
  69.             echo "<div class='alert alert-danger'>";
  70.             echo "<div>{$file_upload_error_messages}</div>";
  71.             echo "<div>Update the record to upload photo.</div>";
  72.             echo "</div>";
  73.         }
  74.  
  75.  
  76.         $stmt->execute();
  77.         //header("Refresh:1");
  78.  
  79.  
  80.     }
  81. }
  82. else{
  83.  
  84.     $avatarQuery = "SELECT id, username, image FROM users WHERE username = '$username'";
  85.     $avatarStmt = $pdo->prepare( $avatarQuery );
  86.  
  87.     //$stmt->bindParam(1, $id);
  88.  
  89.     $avatarStmt->execute();
  90.  
  91.     // store retrieved row to a variable
  92.     $row = $avatarStmt->fetch(PDO::FETCH_ASSOC);
  93.     $avatar = htmlspecialchars($row['image'], ENT_QUOTES);
  94.  
  95. }
  96.  
  97.  
  98. }?>
  99. <!doctype html>
  100. <html lang="en">
  101. <head>
  102.  
  103.     <link rel="shortcut icon" href="images/logoNew_bubbles.png"/>
  104.     <link type="text/css" rel="stylesheet" media="screen"
  105.           href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
  106.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
  107.           integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  108.     <link href="css/styles.css" rel="stylesheet">
  109.     <link rel="stylesheet" href="css/test.css">
  110.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
  111.           integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  112.  
  113.     <meta charset="utf-8">
  114.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  115.     <meta name="description" content="">
  116.     <meta name="author" content="">
  117.  
  118.     <title>User Dashboard</title>
  119.  
  120.  
  121. </head>
  122.  
  123.  
  124. <body class="text-center" style="background-color:#eee">
  125.  
  126. <header class="fixed-top">
  127.     <?php include_once "php_includes/header.php"; ?>
  128. </header>
  129.  
  130. <div class="container" style="margin-top: 100px; margin-bottom: 150px;">
  131.     <div class="col-sm-1"></div>
  132.     <div class="col-sm-10" style="text-align:center; margin-top: 50px">
  133.         <div class="row">
  134.             <div class="col-lg-12">
  135.                 <h2>Profile</h2>
  136.                 <p><?php echo $avatar ? "<img src='uploads/{$avatar}' style='width:300px;' />" : "<img src='images/avatar.jpg' style='width:300px;';>"  ?></p>
  137.             </div>
  138.         </div>
  139.         <div>
  140.             <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
  141.                 <div class="row justify-content-md-center mb-1">
  142.                     <div class="col-md-3">tr</div>
  143.                     <div class=" col-md-auto">
  144.                         <input class="form-control-file" type="file" name="image" id="image">
  145.                     </div>
  146.                     <div class="col-md-1">ty</div>
  147.                 </div>
  148.                 <input class="btn btn-success mb-1" type="submit" value="Upload Image" name="submit">
  149.                 <div class="border rounded my-5 py-3 ">
  150.                     Lorem Ipsum is simply dummy text of the printing and typesetting industry.
  151.                     Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when
  152.                     an unknown printer took a galley of type and scrambled it to make a type specimen book.
  153.                     It has survived not only five centuries,
  154.                 </div>
  155.                 <div class="form-group">
  156.                     <label> Info about me </label>
  157.                     <textarea id="infoAboutMe" name="infoAboutMe" class="form-control" rows="5"></textarea>
  158.                 </div>
  159.  
  160.  
  161.  
  162.             </form>
  163.  
  164.         </div>
  165.         <div>
  166.             <h2 class="welcome mt-5 ">My Favorite Beers</h2>
  167.         </div>
  168.         <div class="row justify-content-md-center my-3 py-3">
  169.             <div class="polaroid rounded col-sm-4">
  170.                 <div class="col-md">
  171.                     <img src="images/heineken.png">
  172.                     <p>Beer 1</p>
  173.                 </div>
  174.             </div>
  175.             <div class="polaroid rounded col-sm-4">
  176.                 <div class="col-md">
  177.                     <img src="images/heineken.png">
  178.                     <p>Beer 2</p>
  179.  
  180.                 </div>
  181.             </div>
  182.             <div class="polaroid rounded col-sm-4 ">
  183.                 <div class="col-md">
  184.                     <img src="images/heineken.png">
  185.                     <p>Beer 3</p>
  186.                 </div>
  187.             </div>
  188.         </div>
  189.         <div>
  190.             <div class="row my-3">
  191.                 <button class="btn btn-warning shanoClass">Save Changes</button>
  192.             </div>
  193.         </div>
  194.         <div class="justify-content-md-center row my-3">
  195.             <button class="btn btn-warning mx-3">Change info</button>
  196.             <button class="btn btn-warning mx-3">My orders</button>
  197.         </div>
  198.         <div class="justify-content-md-center row my-3">
  199.             <button class="btn btn-warning mx-3">My wallet</button>
  200.             <button class="btn btn-warning mx-3">Basket</button>
  201.         </div>
  202.     </div>
  203.     <div class="col-sm-1"></div>
  204. </div>
  205.  
  206.  
  207. <footer class="container fixed-bottom">
  208.  
  209.     <?php include_once "php_includes/footer.php"; ?>
  210. </footer>
  211.  
  212. <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
  213. <script>
  214.     $(document).ready(function () {
  215.         $("#profile").addClass('text_shadow');
  216.     });
  217. </script>
  218.  
  219.  
  220. </body>
  221.  
  222. </html>
Advertisement
Add Comment
Please, Sign In to add comment