views:

66

answers:

1

Hi

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

A: 

Is there a mismatch in the field names you're using?

It looks like you're using "file" on the iphone:

[request setPostValue:@"login.zip" forKey:@"file"];  

but 'uploaded' on the server:

$target = $target . basename( $_FILES['uploaded']['name']) ; 

Try changing these to be the same.

JosephH
i changed them. still not working. :(
Nick
What happens? Are there any errors in the server log file? Does the data get sent to the server?
JosephH
No error on Error log. Access log reads "152.96.15.90 - - [22/Jul/2010:13:31:57 +0200] "POST /test/upload.php HTTP/1.1" 200 561" i don't understand and it's driving me insane. :( :((
Nick