Reputation: 11
I am using this code to upload a picture from my mobile on my php website mobile version. The problem is for a strange reason the image get rotated. I need a solution as I have been trying in vain till now.
The code I am using for my php site is :
<?php
if (isset($_FILES["pics"]["name"]) )
{
$errors= array();
foreach($_FILES['pics']['tmp_name'] as $key => $tmp_name )
{
$file_name = $key.$_FILES['pics']['name'][$key];
$file_size =$_FILES['pics']['size'][$key];
$file_tmp =$_FILES['pics']['tmp_name'][$key];
$file_type=$_FILES['pics']['type'][$key];
$file_name1[] = $file_name;
$desired_dir="users/timeline/".$_SESSION['session_uid'];
if(empty($errors)==true)
{
if(is_dir($desired_dir)==false)
{
mkdir("$desired_dir", 0777); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false)
{
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}
else
{ // rename the file if another one exist
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
}
}
}
?>
HELP PLEASE :)
Upvotes: 1
Views: 966
Reputation: 156
Ok, did some Googling. Your code is fine, the image is rotated before it is upload. I am assuming you are using an iPhone so here is a great resource to help you with your problem:
http://iphonephotographyschool.com/iphone-photos-upside-down/
From the link above:
"Your iPhone doesn’t convert any images to correct orientation because that would keep it busy for a few seconds. Instead it simply saves all photos as they were recorded and adds information about their correct orientation to EXIF tags. This means that your iPhone is ready to shoot another photo within a fraction of a second, which is just awesome."
Upvotes: 1