class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
more info about the class
$exif = exif_read_data($_FILES['Filedata']["tmp_name"]); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: echo 2; $handle->image_rotate = 270; break; case 3: echo 3; $handle->image_rotate = 180; break; case 6: echo 4; $handle->image_rotate = 90; break; } }