Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone IOS 5 Upload.CAF到web服务器,但为空_Iphone_Objective C_Ios_Upload_Caf - Fatal编程技术网

Iphone IOS 5 Upload.CAF到web服务器,但为空

Iphone IOS 5 Upload.CAF到web服务器,但为空,iphone,objective-c,ios,upload,caf,Iphone,Objective C,Ios,Upload,Caf,我正在尝试将录制的.caf文件上载到我的web服务器。文件在那里,因为它在录制后播放,而且我的播放配置也正确,因为我可以在我的应用程序中从服务器播放常规的.caf文件。然而,当我上传caf时,php脚本返回一个成功,并且创建了一个文件,该文件应该是上传的.caf文件,但该文件要么为空,要么为2字节大小。我知道该文件不正确,因为当我下载该文件并将其放入音频编辑软件时,它是空白的。 我有以下目标C代码: NSString *file2 = [[NSBundle mainBundle] pat

我正在尝试将录制的.caf文件上载到我的web服务器。文件在那里,因为它在录制后播放,而且我的播放配置也正确,因为我可以在我的应用程序中从服务器播放常规的.caf文件。然而,当我上传caf时,php脚本返回一个成功,并且创建了一个文件,该文件应该是上传的.caf文件,但该文件要么为空,要么为2字节大小。我知道该文件不正确,因为当我下载该文件并将其放入音频编辑软件时,它是空白的。 我有以下目标C代码:

    NSString *file2 = [[NSBundle mainBundle] pathForResource:filePath ofType:@"caf"];
NSData *file1Data = [[NSData alloc] initWithContentsOfFile:file2];
NSString *urlString = @"http://sayroom.com/SR_Mobile_App/scripts/upload_audio.php";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"thefile.caf\"\r\n"]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:file1Data]];
    [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"Return String= %@",returnString);
NSLog(@"Audio Sent Successfully");
以下是我的php代码:

    $uploaddir = 'audio/';
    $file = basename($_FILES['userfile']['name']);
    $uploadfile = $uploaddir . $file;

    if(!$_FILES['userfile']['tmp_name']){
echo "no file";
exit();
    }

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo $_FILES['userfile']['tmp_name']."done";
    } else {
    echo "ERROR";
    }
我整天都在为这个问题焦头烂额,在网上找不到任何帮助。我尝试了很多方法,但还没有看到任何进展

有什么想法吗