gpt4 book ai didi

php - 视频上传,只上传20秒以下的视频

转载 作者:行者123 更新时间:2023-11-29 04:55:01 27 4
gpt4 key购买 nike

好吧,这就是我的问题,我需要我的用户能够上传视频,视频可以是任何大小,所以我编写了一个 php 脚本来处理将文件放置在正确的位置..这里是我的代码:

-(IBAction)upload:(id)sender{
[self post:webdata];
}

webdata 是视频数据,这是我设置它的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
[self dismissModalViewControllerAnimated:YES];
//assign the mediatype to a string
//check the media type string so we can determine if its a video
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
webData = [[NSData alloc]init];
webData = [NSData dataWithContentsOfURL:videoURL];
//[self post:webData];
video = 1;
upload.hidden = NO;

ImagesCopy = [[NSMutableArray alloc]initWithObjects:@"1", nil];
[tableview reloadData];


}

好的,现在我已经完成了 web 数据,现在我需要通过调用上面发布的 [self post:webdata 来上传数据

- (void)post:(NSData *)fileData

{

NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:[self saveUserLogin]];

int test;
NSString *string = [array objectAtIndex:3];
test = [string intValue];
test++;
NSData *videoData = fileData;
NSString *urlString = [[NSString alloc]initWithFormat:@"http://www.site.com/members/uploadMovie.php?&username=%@", [array objectAtIndex:0]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:100000000000];
[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]];
NSString *postName = [[NSString alloc]initWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"vid%i.mov\"\r\n", test];
[body appendData:[[NSString stringWithString:postName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"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];
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if (connection) {
responceData = [NSMutableData data];

}
else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Well something went wrong, make sure you have a valid internet connection and try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
// NSLog(@"%@", returnString);

NSArray *values = [[NSArray alloc] initWithObjects: [array objectAtIndex:0],[array objectAtIndex:1], [array objectAtIndex:2], [NSString stringWithFormat:@"%i", test], nil];
[values writeToFile:[self saveUserLogin] atomically:YES];

}

好的,现在我需要调用一些方法:

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responceData appendData:data];

}

-(void)connection:(NSURLConnection *)connection didSendBodyData (NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{

if([connecting isAnimating]){
[connecting stopAnimating];
[connectingImage removeFromSuperview];
[connecting removeFromSuperview];
}
float progress = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
float total = [[NSNumber numberWithInteger: totalBytesExpectedToWrite] floatValue];
progressForUpload.progress = progress/total;

}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {

NSString* responseString = [[NSString alloc] initWithData:responceData encoding:NSUTF8StringEncoding];
NSLog(responseString);
progressForUpload.progress = 0;

[ImagesCopy removeObjectAtIndex:0];
[tableview reloadData];

if (ImagesCopy.count == 0) {
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];

[self.delegate didFinishController:self];
}
}

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
UIAlertView *erroragain = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Something went wrong, this might be a server problem, log out and try again, if its still not working, wait a hour and try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[erroragain show];
}

所以这段代码运行良好,视频被上传(如果它在 20 秒内),现在看看我的 php 代码:

<?php


$dbc = mysql_connect('hosting', 'user', 'pass');
if(!$dbc){
die('not connected : ' . mysql_error());
}

$db_selected = mysql_select_db("db", $dbc);
if(!$db_selected){
die("could not connect to DB : " . mysql_error());
}

$username = $_GET['username'];

$check = mysql_query("SELECT video FROM members WHERE username='$username'");

$findMem = mysql_num_rows($check);

if($findMem > 0){
while($row = mysql_fetch_array($check) or die(mysql_error())){

$vid = $row['video'];

$vid = $vid + 1;

mysql_query("UPDATE members SET video='$vid'
WHERE username='$username'");

$uploaddir = './'.$username.'/default/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "done";


}
else{
echo "error";
}
}
}
?>

所以我真的不明白这个问题,如果它上传的视频少于 20 秒,它应该能够做得更长,对吗?

如果有人可以帮我弄清楚这有什么问题,我需要能够上传更大的视频,我尝试在 php 代码中调用 sleep(5) 看看是否可以该文件只是需要一些时间来处理,但没有成功。

谢谢,雅各布

最佳答案

听起来您遇到了文件上传大小限制、执行时间限制、内存限制或磁盘空间限制。您可以在 PHP.ini 中更改这些。

此外,您对 SQL 注入(inject)开放,如果您不学会使用 PDO 进行准备好的查询,或者至少逃避您的攻击,那么您将会被黑客攻击。数据。

关于php - 视频上传,只上传20秒以下的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8161190/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com