title: Uploading an image to a server through imagepicker doesnt work (need solution)
body: <p>As a follow up from this question <a href="https://stackoverflow.com/questions/9349318/uploading-images-to-server-doesnt-work/">Uploading images to server doesn&#39;t work</a> (There you can find my php file) I realized why it isn't working. But I don't know the solution. As you can see in the code (a few lines down) I give my image to the php file, but it doesnt recognize it as an image. So I hope someone can help with it and knows the (probably obvious) solution:</p>
  
  <pre><code> - (IBAction)changepic:(id)sender{
  
      picker = [[UIImagePickerController alloc] init];
      picker.delegate = self;
      picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      [self presentModalViewController:picker animated:YES];
      }
  
   - (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
  
  double compressionRatio=1;
  NSData *imageData=UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage],compressionRatio);
  while ([imageData length]&gt;50000) { 
      compressionRatio=compressionRatio*0.50;
      imageData=UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage],compressionRatio);
  }
  
  UIImage *yourUIImage;
  yourUIImage = [info objectForKey:UIImagePickerControllerOriginalImage];
  imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
  [[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"bild"];
  [[NSUserDefaults standardUserDefaults] synchronize];
  
  
  
  NSData *imageData2 = UIImageJPEGRepresentation(yourUIImage, 90);
  NSString *urlString = @"http://myserver/upload.php";
  
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setURL:[NSURL URLWithString:urlString]];
  [request setHTTPMethod:@"POST"];
  
  NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
  NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
  [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
  
  NSMutableData *body = [NSMutableData data];
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"imagename.jpg\"\r\n",index] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  [body appendData:[NSData dataWithData:imageData2]];
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  // setting the body of the post to the reqeust
  [request setHTTPBody:body];
  
  NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  
  NSLog(@"%@", returnString);
  
  [self dismissModalViewControllerAnimated:YES];
  }
  </code></pre>