title: My script can uploads the Avatar/Profile image but can't change the size (height and width)
body: <p>Thanks for the support really appreciated.</p>
  
  <p>I am newbie in PHP, and i heard that i can find my solution from those PHP expert who are here in Stackoverflow.</p>
  
  <p>I have bought <a href="http://codecanyon.net/item/php-security-user-management/141801?WT.ac=solid_search_item&amp;WT.seg_1=solid_search_item&amp;WT.z_author=hunzonian" rel="nofollow">this</a> script a while ago and now the producer stopped offering support.</p>
  
  <p>Avatar upload form</p>
  
  <p><a href="http://i.stack.imgur.com/YO7PD.jpg" rel="nofollow">http://i.stack.imgur.com/YO7PD.jpg</a></p>
  
  <p><strong>My Question</strong></p>
  
  <p>The script have ability to upload profile for every user but it doesn't resize the image.
  If  a user upload a 2 mb image so the script use 2 mb image in all over the website which makes my website to run slower.</p>
  
  <p>I want that the script should resize the image to </p>
  
  <p>([width=100px and height=auto] and </p>
  
  <p>[width=19px and height=auto])</p>
  
  <p>so i use a lighter image in size (like ~150 kb and ~55kb) and let my site run faster.</p>
  
  <p><strong>This is the avatar.php file that process the uploading</strong></p>
  
  <pre><code>    &lt;?php
  // declare variables
  $msg = '';
  $f_avatar_image = '';
  // ------------------------------------------------------------
  // UPLOAD AVATAR
  // ------------------------------------------------------------
  if(isset($_POST['btnUploadAvatar']) &amp;&amp; !empty($_FILES['fileUpload']['name']))
  {
      // create variables
      $avatar_directory = AVATAR_FILE_DIRECTORY;
      $file_name = $_FILES['fileUpload']['name'];
      $file_type = $_FILES['fileUpload']['type'];
      $file_size = $_FILES['fileUpload']['size'];
      $file_size_limit = AVATAR_FILE_SIZE;
      $calc_kilobites = 1024;
      $file_size_kb = round($file_size / $calc_kilobites, 2);
      $temp_file_name = $_FILES['fileUpload']['tmp_name'];
      $upload_error = $_FILES['fileUpload']['error'];
  
  
      // create unique file name
      $unique_file_name = $user_name.'-'.$file_name;
      $avatar_img_url = AVATAR_IMAGE_URL.$user_name.'-'.$file_name;
  
      // if upload error display error message
      if($upload_error &gt; 0)
      {
          echo 'ERROR:' . $upload_error;
      }
  
      // if no upload error - check for file types
      if($upload_error == 0 &amp;&amp;
      $file_type == 'image/gif' ||
      $file_type == 'image/jpeg' ||
      $file_type == 'image/png' )
      {
          // if file size is within limits
          if($file_size &lt;= $file_size_limit)
          {
              // move uploaded file to assigned directory
              if(move_uploaded_file($temp_file_name, $avatar_directory . $unique_file_name))
  
              {
                  // get user id
                  $get_user_id = mysqli_query($conn, "SELECT UserId FROM users WHERE UserName = '$user_name' Limit 1") or die($dataaccess_error);
  
                  // if user id exist
                  if(mysqli_num_rows($get_user_id) == 1 )
                  {
                      $row = mysqli_fetch_array($get_user_id);
                      $user_id = $row['UserId'];
  
                      // check if user profile already exist
                      $check_user_profile = mysqli_query($conn, "SELECT UserId FROM profiles WHERE UserName = '$user_name' Limit 1") or die($dataaccess_error);
  
                      // if user profile exist - update
                      if(mysqli_num_rows($check_user_profile) == 1 )
                      {
                          // update profiles
                          $update_profile = mysqli_query($conn, "UPDATE profiles SET AvatarImage = '$avatar_img_url' WHERE UserName = '$user_name'") or die($dataaccess_error);
  
                          if(mysqli_affected_rows($conn) &gt; 0)
                          {
                              echo 'Upload Success! &lt;br/&gt;';
                              echo 'File Name: '.$file_name.'&lt;br/&gt;';
                              echo 'File Type: '.$file_type.'&lt;br/&gt;';
                              echo 'File Size: '.$file_size_kb.' Kb &lt;br/&gt;';
                              $msg = $profile_update_success;
                          }
                          else
                          {
                              $msg = $profile_update_failed;
                          }
                      }
                      else
                      {
                          // create profile
                          $insert_profile = mysqli_query($conn, "INSERT INTO profiles(UserId,UserName,AvatarImage) VALUES($user_id,'$user_name','$avatar_img_url')") or die($dataaccess_error);
  
                          if(mysqli_affected_rows($conn) &gt; 0)
                          {
                              echo 'Upload Success! &lt;br/&gt;';
                              echo 'File Name: '.$file_name.'&lt;br/&gt;';
                              echo 'File Type: '.$file_type.'&lt;br/&gt;';
                              echo 'File Size: '.$file_size_kb.' Kb &lt;br/&gt;';
                              $msg = $profile_update_success;
                          }
                          else
                          {
                              $msg = $profile_create_failed;
                          }
                      }
                  }
                  else
                  {
                      // user id not found
                      $msg = $profile_update_failed2;
                  }
              }
              else
              {
                  $msg = $avatar_upload_failed;
              }
          }
          else
          {
              $msg = $avatar_file_too_large;
          }
      }
      else
      {
          $msg = $avatar_wrong_file_type;
      }
  }
  elseif(isset($_POST['btnUploadAvatar']) &amp;&amp; empty($_FILES['fileUpload']['name']))
  {
      $msg = $avatar_empty;
  }
  
  
  // ------------------------------------------------------------
  // DISPLAY AVATAR ON PAGE LOAD
  // ------------------------------------------------------------
  if($user_name)
  {
      // get user id
      $get_avatar_image = mysqli_query($conn, "SELECT AvatarImage FROM profiles WHERE UserName = '$user_name' Limit 1") or die($dataaccess_error);
  
      if(mysqli_num_rows($get_avatar_image) == 1)
      {
          $row = mysqli_fetch_array($get_avatar_image);
          if($row['AvatarImage'] != 'NULL' &amp;&amp; $row['AvatarImage'] != '')
          {
              $f_avatar_image = $row['AvatarImage'];
          }
          else
          {
              $f_avatar_image = AVATAR_IMAGE_URL.DEFAULT_AVATAR_IMAGE;
          }
      }
      else
      {
          $f_avatar_image = AVATAR_IMAGE_URL.DEFAULT_AVATAR_IMAGE;
      }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>This is the avatar.html.php file form</strong></p>
  
  <pre><code>    &lt;?php require_once(ROOT_PATH.'user/modules/accordion/avatar.php'); ?&gt;
  &lt;div class="profileWrap"&gt;
    &lt;form name="frmAvatar" method="post" action="" enctype="multipart/form-data" class="htmlForm"&gt;
      &lt;div class="infoBanner2"&gt;
        &lt;p&gt;REQUIREMENTS:  File Size: &lt;?php echo AVATAR_FILE_SIZE / 1024 ?&gt; kb max. File Type: gif, jpg, png&lt;/p&gt;
      &lt;/div&gt;
      &lt;!-- error msgs --&gt;
      &lt;ul&gt;
      &lt;?php echo $msg; ?&gt;
      &lt;/ul&gt;
      &lt;p&gt;&lt;input name="selectFile" type="image" src="&lt;?php echo $f_avatar_image; ?&gt;" class="img"&gt;&lt;/p&gt;
      &lt;p&gt;&lt;label for="fileUpload"&gt;Avatar Image:&lt;/label&gt;&lt;input name="fileUpload" type="file" id="fileUpload" maxlength="255" &gt;&lt;/p&gt;
      &lt;input name="btnUploadAvatar" type="submit" value="Upload" class="gvbtn btn" onclick="return confirm('Are You READY to UPLOAD?');"/&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>The avatar.php file is linked to a configuration file (web.config.php) file</strong></p>
  
  <pre><code>// ------------------------------------------------------------
  // 16. AVATAR IMAGE FILE
  // ------------------------------------------------------------
  define('AVATAR_FILE_SIZE', 2097152); // 50 Kb max. -&gt; 1 kilobyte = 1024 bytes
  define('AVATAR_FILE_DIRECTORY', ROOT_PATH.'user/upload/avatars/'); // upload directory
  define('AVATAR_IMAGE_URL', SITE_URL.'user/upload/avatars/'); // default avatar url
  define('DEFAULT_AVATAR_IMAGE', 'default-avatar.png'); // default avatar image
  </code></pre>
  
  <p><strong>If you needed to ask anything i am ready to answer.
  Let me thank the one who answer it</strong>.</p>