Advertisement
karlokokkak

Untitled

Apr 3rd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2.  
  3. $username = trim( isset($_SESSION['username']) ? $_SESSION['username'] : "" );
  4. $userPic = isset($_SESSION['userPic']) ? $_SESSION['userPic'] : "";
  5. var_dump($userPic);
  6.  
  7.  
  8. $info = date('Y-m-d_H-i-s');
  9.  
  10. if(!empty($username))
  11. {
  12.     if (isset($_FILES['fileToUpload'])) {
  13.       $errors= array();
  14.       $file_name = $_FILES['fileToUpload']['name'];
  15.       $file_size = $_FILES['fileToUpload']['size'];
  16.       $width = 1500;
  17.       $height = 1500;
  18.       $file_tmp = $_FILES['fileToUpload']['tmp_name'];
  19.       $file_type = $_FILES['fileToUpload']['type'];
  20.       $tmp = explode('.',$_FILES['fileToUpload']['name']);
  21.       $file_ext=strtolower (end ($tmp));
  22.  
  23.       $extensions= array("jpeg","jpg","png");
  24.  
  25.       if(in_array($file_ext,$extensions)=== false){
  26.          $errors[]="extension not allowed, please choose a JPEG or PNG file.";
  27.       }
  28.  
  29.        if ($file_size > 8097152) {
  30.         $errors[] = 'File size must be 2 MB';
  31.     }
  32.  
  33.       if ($width > 1500 || $height > 1500) {
  34.             echo"File is to large";
  35.       }
  36.  
  37.       if(empty($errors)==true)
  38.       {
  39.         $userPic = date('Y-m-d_H-i-s').$file_name;
  40.          move_uploaded_file($file_tmp,"uploads/".$userPic);
  41.  
  42.       $stmt = $conn->prepare("UPDATE users SET userPic=?, date_time=? WHERE username = ?");
  43.       $date_time = date("Y-m-d H:i:s");
  44.       $stmt->bind_param('sss', $userPic, $date_time, $username);
  45.  
  46.       /* execute prepared statement */
  47.        $stmt->execute();
  48.  
  49.      printf("%d Row inserted.\n", $conn->affected_rows);
  50.  
  51.      /* close statement and connection */
  52.  
  53.       }else{
  54.          print_r($errors);
  55.          echo"Couldn't upload picture";
  56.       }
  57.  
  58.     }
  59. }
  60. else
  61. {
  62.     echo "Invalid Username";
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement