I'm currently sending JSON data from my iOS app to a PHP script on my web server. Here's the code I'm using in iOS to send the data:
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:newDatasetInfo options:kNilOptions error:&error];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL: [NSURL URLWithString:@"http://www.myserver.com/upload.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPBody:jsonData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
And on the PHP side:
$handle = fopen('php://input','r');
$jsonInput = fgets($handle);
// Decoding JSON into an Array
$decoded = json_decode($jsonInput,true);
How can I modify both the iOS code and the PHP code to be able to also upload a file from the iOS app to the PHP code, that the PHP code then uses to write to disk locally? The file would be an audio file.
Thanks!