我已經編寫了一個應用程序,它使用該數據庫上的PHP文件將照片上傳到遠程數據庫。問題是,當從網站上讀取照片或從鏈接加載照片時,圖像呈現在橫向上。 有一部分應用程序顯示這個圖像,當在應用程序中加載時方向是正確的,所以我認爲它是爲了做到這一點而獲取exif數據? 我的問題基本上是如何在上傳之前旋轉UIImage對象,或者如何更改PHP數據,以便將它放在數據庫中正確的方向?從應用使用ASIHTTPRequest iPhone上傳的JPEG圖像方向
代碼:
// 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];
的代碼示例難道不爲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;
什麼是'[自我更新:文件名]'在你的代碼? – Illep 2012-02-14 00:59:06