I have written an app which takes a photo and uploads it to a remote database using a PHP file on that database. The problem is that when the photo is read from a website or just loaded from the link, the image is presented in landscape. There is a part of the app which displays this image, the orientation is correct when loaded in the app so I presume it is getting the exif data in order to do this? My question basically is how do I rotate either the UIImage object before its uploaded or how do I change the PHP data so it will place it in the database in the correct orientation?
Code from app:
// Display the activity indicator
[myActivityIndicator startAnimating];
//Set up variables and copy image into NSData compressed
srandom(time(NULL));
NSURL *url = [NSURL URLWithString:@"http://www.mydomain/test-upload.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSData *compressedImageData = UIImageJPEGRepresentation(theImageView.image, 0.5f);
//set the filename to a random number
int randomNumber = (random() % 250000);
NSString* fileName = [NSString stringWithFormat:@"%d.jpg", randomNumber];
// Set the filename and upload
[request setFile:compressedImageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"photo"];
[request setDelegate:self];
[self Update:fileName];
//Create a location manager and start it uploading (delegate : Location update)
[request startAsynchronous];
The code sample wouldnt work for the PHP:
$uploaddir = 'images/';
$file = basename($_FILES['photo']['name']);
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile)) {
echo "http://www.mysite.com/{$file}";
}
else {
$isfile = $_FILES['photo'];
if(file_exists($file)) {
echo 'file exists';
} else {
echo 'File not found!';
}
echo "fail";
echo "Name is" . $file;