title: How to check/fix image rotation before upload image using PHP
body: <p>I have a issiue when uploading a image taken using iphone.
  I am trying to use PHP and the imgrotate function to automaticly decide if the image needs to be rotated to the correct possition, before uploading it to the server.</p>
  
  <p><strong>My html code:</strong></p>
  
  <pre><code>&lt;form class="form-horizontal" method="post" enctype="multipart/form-data"&gt;  
       &lt;div class="form-group"&gt;
          &lt;div class="col-md-9"&gt;
              &lt;div class="input-group"&gt;
                  &lt;span class="input-group-btn"&gt;
                      &lt;span class="btn btn-default btn-file"&gt;
                          Choose img&lt;input type="file" name="file" id="imgInp"&gt;
                      &lt;/span&gt;
                  &lt;/span&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;button type="submit"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>The PHP code im using:</strong>
  Also return a error: Warning: imagerotate() expects parameter 1 to be resource, string given in.</p>
  
  <p>Anyone have a working code for this scenario?</p>
  
  <pre><code>&lt;?php
  
  $filename = $_FILES['file']['name'];
  $exif = exif_read_data($_FILES['file']['tmp_name']);
  
  
   if (!empty($exif['Orientation'])) {
          switch ($exif['Orientation']) {
              case 3:
                  $image = imagerotate($filename, -180, 0);
                  break;
              case 6:
                  $image = imagerotate($filename, 90, 0);
                  break;
              case 8:
                  $image = imagerotate($filename, -90, 0);
                  break;
          } 
      }
  
      imagejpeg($image, $filename, 90);
  
  ?&gt;
  </code></pre>