title: How should I adjust the orientation of the image captured and uploaded from smart devices using jQuery/PHP?
body: <p>I'm using <strong>PHP, jQuery, AJAX, HTMl5, Bootstrap framework(v.3.3.0)</strong> for my website.</p>
  
  <p>I'm allowing user to capture photo using device's camera and upload the same to the server. </p>
  
  <p>The issue I'm facing is when I upload such captured image the orientation of image saved on server changes. That means if the orientation of phone is portrait while taking the photo and such portrait orientation image is loaded to the server then the orientation of saved image on server is getting changed to landscape. </p>
  
  <p>How should I avoid this?</p>
  
  <p>Following is my code:</p>
  
  <p><strong>HTML code :</strong></p>
  
  <pre><code>&lt;form id="request_form" method="post" class="form-horizontal" enctype="multipart/form-data" action=""&gt;
    &lt;input type="file" name="student_image" id="student_image" accept="image/*" capture/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>jQuery-AJAX code :</strong></p>
  
  <pre><code>$('#request_form').submit(function(e) {
  
    var form = $(this);
  
    var formdata = false;
  
    if(window.FormData) {
      formdata = new FormData(form[0]);
    }
  
    var formAction = form.attr('action');
  
    $.ajax({
      url         : 'request.php',
      type        : 'POST',    
      cache       : false,
      data        : formdata ? formdata : form.serialize(),
      contentType : false,
      processData : false,
      success: function(response) {
  
        var responseObject = $.parseJSON(response);    
        if(responseObject.error_message) {
  
          if ($(".alert-dismissible")[0]) {
            $('.alert-dismissible').remove();   
          }  
          alert(responseObject.error_message);    
  
        } else {
          alert("Success");       
        }
      }
    });
    e.preventDefault();
  });
  </code></pre>
  
  <p><strong>PHP code :</strong></p>
  
  <pre><code>&lt;?php
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["student_image"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    // Check if image file is a actual image or fake image
    if(isset($_POST["submit"])) {
      $check = getimagesize($_FILES["student_image"]["tmp_name"]);
      if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
      } else {
        echo "File is not an image.";
        $uploadOk = 0;
      }
    }
    // Check if file already exists
    if (file_exists($target_file)) {
      echo "Sorry, file already exists.";
      $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["student_image"]["size"] &gt; 500000) {
      echo "Sorry, your file is too large.";
      $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "jpg" &amp;&amp; $imageFileType != "png" &amp;&amp; $imageFileType != "jpeg" &amp;&amp; $imageFileType != "gif" ) {
      echo "Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.";
      $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
      echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
      if (move_uploaded_file($_FILES["student_image"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["student_image"]["name"]). " has been uploaded.";
      } else {
        echo "Sorry, there was an error uploading your file.";
      }
    }
  ?&gt;
  </code></pre>
  
  <p>The issue is not in uploading the file. The file is getting uploaded. The issue is with the change in orientation of the uploaded image. I want to avoid that thing. The orientation of the captured and uploaded image should be the same.</p>
  
  <p>If you need any further information regarding my issue please do let me know.</p>
  
  <p>Thanks in advance.</p>