iPhone image uploading with PHP on the server
All I want to achieve is to upload an image from the iPhone to a server running a PHP script.
I've stripped down the iPhone code to this:
NSString *url = @"http://www.domain.com/upload.php";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: url]];
[request setHTTPMethod: @"POST"];
NSData *data = UIImagePNGRepresentation([UIImage imageNamed:@"theimage.png"]);
[request addValue:[NSString stringWithFormat:@"%ld", [data length]] forHTTPHeaderField:@"Content-Length"];
[request addValue:@"image/png" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: data];
NSURLConnection *conn = [NSURLConnection connectionWithRequest: request delegate: self];
[conn retain];
Questions:
How does the server side PHP script retrieve the contents of what I send via setHTTPBody? I am aware that there are $_REQUEST and $_POST global vars but as I don't give a specific field name, I don't know how to grab the image on the PHP side. ($_REQUEST is a named array and expects a named index as in $_REQUEST["lastname"])
Could you please look into this and help? Thanks!
iMac, Mac OS X (10.5.4), iPhone 16GB, iPhone 3G 16GB, Apple Firmware 2.1 | www.treealitygroup.com