【发布时间】:2013-07-31 11:35:19
【问题描述】:
我必须从 iOS 应用程序发送音频文件并使用 php 存储在 MySQL 中。我已将音频文件转换为 base64string 并发送到服务器。问题是我只能在数据库中存储几个字节的数据。
NSURL *aUrl = [NSURL URLWithString:@"URL"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
NSString *postString = [NSString stringWithFormat:@"audiostring=%@,",audioStr];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(!connection){
NSLog(@"Connection Failed");
}
if($_POST["audiostring"])
{
$sql="insert into AudioDetails (audiostring)values('$_POST[audiostring]')";
$result=mysql_query($sql) or die(mysql_error());
}
以上是iOS和php的代码。
【问题讨论】:
-
如果不需要将文件存储在数据库中,我建议您考虑将文件存储在文件系统中,这是一种更好的方法,因为它是二进制文件。