您好我正在尝试使用PHP将音频/视频文件上传到服务器。 它正确上传1MB以下的文件,但对于大于1MB的文件开始失败。我实现了一些1.5MB甚至2MB的上传,但从未变大。知道为什么会这样吗?这是我的PHP代码:
$folder = "../audio/";
if (is_uploaded_file($_FILES['audio']['tmp_name'])) {
if (move_uploaded_file($_FILES['audio']['tmp_name'], $folder.$_FILES['audio']['name'])) {
Echo "File uploaded";
} else {
Echo "File not moved to destination folder. Check permissions";
};
} else {
Echo "File is not uploaded.";
};
这是我的iOS代码:
NSData *audioData = [[NSData alloc] initWithContentsOfURL:recordedFile];
NSString *prefixString = @"Audio";
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString] ;
NSString *uniqueFileName = [NSString stringWithFormat:@"%@_%@", prefixString, guid];
NSString *urlString = @"http://www.myserver.com/uploadaudio.php";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"_187934598797439873422234";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];
[request setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
[request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14" forHTTPHeaderField:@"User-Agent"];
[request setValue:@"http://google.com" forHTTPHeaderField:@"Origin"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"audio\"; filename=\"%@.mp3\"\r\n", uniqueFileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:audioData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%lu", (unsigned long)[body length]] forHTTPHeaderField:@"Content-Length"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@", returnString);