title: PHP/IOS6 prvent image from rotating when uploading from iphone using exif
body: <p>I have a photo upload script written in PHP that works fine on regular pc images, however, when uploading images snapped on an iphone, it rotates them 90 degrees. Apparently, the problem is that the iphone as a newer camera encodes the image with attributes including orientation spelled out in the latest standard and I need to use exif data to correct for this.  I have found two scripts in the PHP manual that use the function exif_read_data($_FILES['file']['name']); to collect the orientation data and then make the necessary adjustements to orient them properly.  However, I cannot get them to work.</p>
  
  <p>First, I am getting an error that says the exif_read_data funcion is invalid even though the manual says it is valid as of PHP 4.2 and I am runnign 5.2.</p>
  
  <p>Second, it is unclear to me what $image really means in these scripts.  Previously, I just used <code>move_uploaded_file($_FILES["file"]["tmp_name"],$target);</code> to effectively upload the file.</p>
  
  <p>Now instead of the file in <code>$_FILES</code>, I am supposed to be uploading <code>$image</code> but I think this may not be the same thing as <code>$_FILES["file"]["tmp_name"]</code>  It may be a string created from the file but at the end of the day, I don't really know what $image is...</p>
  
  <p>Here are the functions fro the PHP manual....</p>
  
  <p>1)</p>
  
  <pre><code>  $exif = exif_read_data($_FILES['file']['name']);
          $ort = $exif['IFD0']['Orientation'];
              switch($ort)
              {
                  case 1: 
  
  // nothing
          break;
  
          case 2: // horizontal flip
              $image-&gt;flipImage($public,1);
          break;
  
          case 3: // 180 rotate left
              $image-&gt;rotateImage($public,180);
          break;
  
          case 4: // vertical flip
              $image-&gt;flipImage($public,2);
          break;
  
          case 5: // vertical flip + 90 rotate right
              $image-&gt;flipImage($public, 2);
                  $image-&gt;rotateImage($public, -90);
          break;
  
          case 6: // 90 rotate right
              $image-&gt;rotateImage($public, -90);
          break;
  
          case 7: // horizontal flip + 90 rotate right
              $image-&gt;flipImage($public,1);   
              $image-&gt;rotateImage($public, -90);
          break;
  
          case 8:    // 90 rotate left
              $image-&gt;rotateImage($public, 90);
          break;
      }
  </code></pre>
  
  <p>2)    </p>
  
  <pre><code>  $image = imagecreatefromstring(file_get_contents($_FILES['file']['name']));
      $exif = exif_read_data($_FILES['file']['name']);
      if(!empty($exif['Orientation'])) {
          switch($exif['Orientation']) {
              case 8:
                  $image = imagerotate($image,90,0);
                  break;
              case 3:
                  $image = imagerotate($image,180,0);
                  break;
              case 6:
                  $image = imagerotate($image,-90,0);
                  break;
          }
      }
  </code></pre>
  
  <p>Prior to encountering this problem, I just used </p>
  
  <pre><code> move_uploaded_file($_FILES["file"]["tmp_name"],$target); to upload file.
  </code></pre>
  
  <p>I have changed this to </p>
  
  <pre><code>move_uploaded_file($image,$target);`
  </code></pre>
  
  <p>When I run this, it is throwing the <code>exif_read_data</code> is not a valid function error and also says <code>file_get_contents</code> and i<code>magecreatefromstring</code> are not valid functions.</p>
  
  <p>Has anyone successfully solved this issue?</p>