Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-09-2009, 09:58 AM   #17 (permalink)
jcafaro10
Registered Member
 
Join Date: Feb 2009
Posts: 88
jcafaro10 is on a distinguished road
Default

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];
}
jcafaro10 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,633
Threads: 94,090
Posts: 402,805
Top Poster: BrianSlick (7,990)
Welcome to our newest member, nor9849
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.