title: Post a UIImage to the web
body: <p>I'm just starting with the xcode business and so far so good, except for this tiny detail: I don't know how to <strong>post a UIImage to the web</strong>. I've been trying everything for the last 3 days (read and queried a lot) without success. The answer, I think is under my nose, still... no luck.  </p>
  
  <p>I leave here the code I wrote (either in objective-c and php): it doesn't work at all!! No image is uploaded. Please, could someone help me?  </p>
  
  <p><strong>//objective-C</strong>  </p>
  
  <pre><code>NSData *theData = UIImagePNGRepresentation(photo.image);  
  NSString *urlString = @"http://www.testes01.com/newsie/receberprofilephoto.php";  
  NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  
  [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 stringWithString:@"Content-Disposition: form-data; name=\"file\"; filename=\"iphoneimage.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];  
  [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];  
  [body appendData:[NSData dataWithData:theData]];  
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];  
  [request setHTTPBody:body];  
  NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];  
  NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];  
  </code></pre>
  
  <p><strong>//PHP</strong>   </p>
  
  <pre><code>move_uploaded_file($_FILES["file"][tmp_name], "fotosprofile/" . $_FILES["file"]["name"]);  
  </code></pre>
  
  <p>Thanks in advance.</p>