Upload file onto Server from the IPhone using ASIHTTPRequest
- by Nick
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