Upload file onto Server from the IPhone using ASIHTTPRequest

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-07-21T15:15:56Z Indexed on 2012/11/09 11:02 UTC
Read the original article Hit count: 185

Filed under:
|
|
|

I've been trying to upload a file (login.zip) using the ASIHTTPRequest libraries from the IPhone onto the inbuilt Apache Server in Mac OS X Snow Leopard. My code is:

 NSString *urlAddress = [[[NSString alloc] initWithString:self.uploadField.text]autorelease];

 NSURL *url = [NSURL URLWithString:urlAddress];

 ASIFormDataRequest *request;  

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);  
 NSString *documentsDirectory = [paths objectAtIndex:0];  
 NSString *dataPath = [documentsDirectory  stringByAppendingPathComponent:@"login.zip"];

 NSData *data = [[[NSData alloc] initWithContentsOfFile:dataPath] autorelease];  

 request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];  
 [request setPostValue:@"login.zip" forKey:@"file"];  
 [request setData:data forKey:@"file"];
 [request setUploadProgressDelegate:uploadProgress];
 [request setShowAccurateProgress:YES];
 [request setDelegate:self];
 [request startAsynchronous];

The php code is :

<?php $target = "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } 
else 
{ echo "Sorry, there was a problem uploading your file."; } ?> 

I don't quite understand why the file is not uploading. If anyone could help me. I've stuck on this for 5 days straight.

Thanks in advance Nik

© Stack Overflow or respective owner

Related posts about php

Related posts about iphone