简体   繁体   English

从 iPhone 应用程序将 mp3 上传到我的(基于 php 的)web 服务器

[英]Uploading an mp3 to my (php based) web server from an iPhone app

I'm looking to upload an mp3 file from my iPhone app to a given php page.我希望将 mp3 文件从我的 iPhone 应用程序上传到给定的 php 页面。 To do this I found the ASIFormDataRequest class. Now I made a piece of code in my app like so:为此,我找到了 ASIFormDataRequest class。现在我在我的应用程序中编写了一段代码,如下所示:

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!!");

However I can't figure out how to put my NSURL which points to the mp3 inside this request.但是我不知道如何将指向 mp3 的 NSURL 放入此请求中。 I have tried the above, but couldn't find anything that points me in the right direction.. Any ideas?我已经尝试过以上方法,但找不到任何指向正确方向的东西。有什么想法吗?

The code that receives the request is like so:接收请求的代码如下:

$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
    }
}

Here:这里:

[request setFile:[soundFileURL absoluteString] forKey:@"mainfile"];

I think you should use [soundFileURL path] instead of [soundFileURL absoluteString] , as [request setFile:] expects a filepath, not a full URL.我认为您应该使用[soundFileURL path]而不是[soundFileURL absoluteString] ,因为[request setFile:]需要文件路径,而不是完整的 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM