使用PHP上传视频时出错

时间:2014-11-03 05:03:29

标签: php xcode server

我正在尝试使用PHP从我的应用程序上传视频,该应用程序基于Xcode,代码工作正常,大小低于10MB,但如果视频更大,我有来自PHP的响应(上传文件时出错,请再试一次!)。

她就是我在Xcode中使用的东西:

- (IBAction)postVideoAction:(id)sender {
if(_postImageView.image == nil)
{
[UIUtils messageAlert:@"Please chose a video" title:@"Ok" delegate:nil];
return;
}

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){


NSData* videoData = [NSData dataWithContentsOfFile:[_videoUrl path]];
long videoSize = [videoData length]/4069/4069;
if(videoSize <= 40) // check size of video
{

NSString *filenames = [NSString stringWithFormat:@"TextLabel"];      //set name here
NSLog(@"%@", filenames);
NSString *urlString = @"http://MyWebSite/sendImages.php";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------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 stringWithFormat:@"Content-Disposition: form-data; name=\"filenames\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[filenames dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *uname = @"TheUserName";
NSString *datestring = @"Photo";
[body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@user%@.mov\"\r\n", uname,datestring]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[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(@"%@",returnString);
NSLog(@"finish");

     }


else {


[UIUtils messageAlert:nil title:@"Video must be less than 160 MB" delegate:self];

if (_conn == nil)
_conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
_ReleaseObj(request);
}
dispatch_async(dispatch_get_main_queue(), ^(void){

});
});

} 

她是PHP文件:

<? 
$myparam = $_FILES['userfile']; 
$target_path = "theUserPhoto/";
if(move_uploaded_file($myparam['tmp_name'], $target_path . basename( $myparam['name'])))

{ echo "The file ". basename( $myparam['name']). " has been uploaded"; } 

else 

{ echo "There was an error uploading the file, please try again!"; } 

?>

正如我所说,代码工作正常但视频大小不到10MB。

任何人都可以帮我找到答案吗?

由于

0 个答案:

没有答案