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

与世无争的帅哥 提交于 2019-12-24 23:47:48

问题


I'm looking to upload an mp3 file from my iPhone app to a given php page. To do this I found the ASIFormDataRequest class. Now I made a piece of code in my app like so:

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 cant figure out how to put my NSURL wich points to the mp3 inside this request. I have tried the above, but couldnt 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
    }
}

Any help would be appreciated :)


回答1:


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.



来源:https://stackoverflow.com/questions/6594582/uploading-an-mp3-to-my-php-based-web-server-from-an-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!