我希望将我的iPhone应用程序中的mp3文件上传到给定的php页面。为此,我找到了ASIFormDataRequest类。现在我在我的应用程序中创建了一段代码:
NSLog(@"fastBackwardButtonLoosened - sending the stuff");
NSString *theUrl = @"MyServerURL";//Sorry not showing this:)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:theUrl]];
[request setFile:[soundFileURL absoluteString] forKey:@"mainfile"];
[request startSynchronous];
NSLog(@"The request was sent!!");
但是我无法弄清楚如何把我的NSURL点到这个请求里面的mp3。我已经尝试了上述内容,但无法找到任何指向正确方向的内容。任何想法?
接收请求的代码如下:
$SafeFile = $HTTP_POST_FILES['mainfile']['name'];
$uploaddir = "uploads/";
$path = $uploaddir.$SafeFile;
if($mainfile != none){ //AS LONG AS A FILE WAS SELECTED...
if(copy($HTTP_POST_FILES['mainfile']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...
//Good
} else {
//Bad
}
}
任何帮助将不胜感激:)
答案 0 :(得分:1)
下面:
[request setFile:[soundFileURL absoluteString] forKey:@"mainfile"];
我认为您应该使用[soundFileURL path]
而不是[soundFileURL absoluteString]
,因为[request setFile:]
需要文件路径,而不是完整的网址。