我一直在尝试使用 ASIHTTPRequest 库从 iPhone 将文件 ( login.zip ) 上传到 Mac OS X Snow Leopard 中的内置 Apache 服务器。我的代码是:
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];
php代码是:
<?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."; } ?>
我不太明白为什么文件没有上传。如果有人可以帮助我。我已经连续坚持了5天。
提前感谢尼克