Ah, one of my posts is missing. I made a PHP upload script (borrowed a php upload script) that's very simple:
Code:
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
I just want it to store a file.
Now on my IPhone is where I have the question. What code goes here? I got myself started by trying to use some of the code you showed me but I'm a bit stuck:
Code:
- (void)applicationWillTerminate:(UIApplication *)application
{
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:locations forKey:kDataKey];//locations is an array
printf("Saving %d Locations",[locations count]);
[archiver finishEncoding];
NSString *post = [NSString stringWithFormat:@"uploadedfile=%@",
[self urlEncodeValue:data]
];//this is the confusing part
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.mywebsite.com/uploader.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
// send it
NSURLResponse* response;
NSError* error;
NSData *serverReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Need to check return data and return status
NSString *replyString = [[NSString alloc] initWithBytes:[serverReply bytes] length:[serverReply length] encoding: NSASCIIStringEncoding];
NSLog(@"NSURLConnection response = %@\nreply = %@", [[response URL] absoluteString], replyString);
//[data writeToFile:[self dataFilePath] atomically:YES];
[archiver release];
[data release];
}