我找到了如何做到这一点。您可以使用asi-http-request上传任何文件。
使用此代码:
// Upload archive
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *archivePath = [documentDirectory stringByAppendingPathComponent:@"CreatedArchive.zip"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://your.url/uploadfile.php"]];
[request setPostValue:@"uploadfilefromapp" forKey:@"action"];
[request setFile:archivePath forKey:@"arch"];
[networkQueue addOperation:request];
[networkQueue go];
上传文件.php
<?php
if(isset($_POST['action']) && isset($_FILES['arch'])) {
if($_POST['action']==='uploadfilefromapp') {
$newfile = basename($_FILES['arch']['name']);
if(move_uploaded_file($_FILES['arch']['tmp_name'], $newfile)) {
echo 'ok!';
} else {
echo 'fail!';
}
} else {
echo 'Go away cheater';
}
}
?>
它正在工作,但如果您知道更好的解决方案,请在此处发布。