Advertisement
karlokokkak

Untitled

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