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
Try this:
or if you can put your zip file into NSData like this
and send it to server with
on the server try this
in
$_FILES['file']['name']
the['file']
MUST be the same asforKey:@"file"
in your requestIs there a mismatch in the field names you're using?
It looks like you're using "file" on the iphone:
but 'uploaded' on the server:
Try changing these to be the same.