Sorry for my ignorance. I can't quite get a hang of it all yet.
So currently I have the code:
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"image.png"]);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:@"http://xyz.co.uk/zyx/imageupload.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"image/png"
forHTTPHeaderField:@"Content-type"];
[request setValue:[NSString stringWithFormat:@"%lu",
(unsigned long)[imageData length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[self imageDataToSend]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
imageupload.php
:
<?php
$handle = fopen("image.png", "wb"); // write binary
fwrite($handle, $HTTP_RAW_POST_DATA);
fclose($handle);
print "Received image file.";
?>
Which uploads a photo to my website... Perfect... NO!
I have noticed some problems.
- There is no loading gif at the top of the iphone indicating any kind of activity.
- There is no way to create a delegate sector so that I can indicate if there has been an error or success.
I then looked towards this. Which was all well and good until I realised that it infact was rubbish and I have received a million errors on trying to upload it. Also everyone told me that I am going in the wrong direction "ASIHTTPRequest is old. You should use AFNetworking".
And I am now trying to work with AFNetworking but it is proving to be extremely difficult! I can't see how it is similar to ASIHTTPRequest at all.
Can anybody help me do the equivelant kind of thing with AFNetwork. Or a whole knew way of uploading image data to my php file.