我花了几个小时阅读有关如何将大文件上传到服务器的内容。这些视频文件的大小为数百兆字节,格式为.mp4。
我的第一次尝试是使用PHP处理POST,但由于php.ini和httpd.conf的限制,这不适用于超过2MB的文件。
一些用户只是简单地将这些限制增加到他们需要的级别,并希望上传能起作用。
一些网站似乎正在使用flash上传工具,但我尝试过的那些很难,而且从来没有明确提到过它们是否解决了上传大小的问题。
我还研究了使用PHP作为客户端的FTP,但我找到的所有示例都是在文件经过POSTed之后简单地将其传输到FTP服务器。FTP使用单独的客户端是不可能的,因为文件名和相关数据存储在数据库中。
目前,我在本地主机上操作,该站点将从我有物理访问权限的机器上提供服务,但我仍然对增加max_upload_size和相关要求持谨慎态度,因为最终我想要转移到托管服务。
最好的解决方案是什么?有没有办法完全通过PHP和HTML上传大文件?如果不是,上传大文件的最佳解决方案是什么,同时仍然能够将文件名传递到数据库?
感谢所有回答的人
发布于 2013-03-07 03:52:30
标准的基于表单的文件上传对您不起作用,因为文件是在单个HTTP POST请求中上传的。
如果你正在寻找一个内置到网站中的解决方案,你应该考虑使用一些上传组件,它可以将文件收缩到客户端,在单独的请求中发送每个块,并将文件放在服务器上。这些组件作为浏览器扩展运行。尽管现在每个人都沉迷于HTML5,没有人喜欢Java和ActiveX组件,但Java最适合您的任务。
发布于 2013-06-27 03:12:44
我认为使用PHP进行编程总是会受到HTTP文件上传的限制。我会使用像Simple2FTP这样的应用程序,而不是尝试用PHP编写一些可行的程序。http://www.simple2ftp.com使用PHP脚本处理用户和管理文件,JavaScript通过FTP完成实际的上传。
发布于 2013-05-10 19:38:20
NSString *LAction=@"post_add";
NSString *urlstring=[appDelegate.SmartAutoString stringByAppendingPathComponent:[NSString stringWithFormat:@"smartautoXml.php"]];
//NSLog(@"urlstring....%@",urlstring);
NSURL *nsurl =[NSURL URLWithString:urlstring];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:nsurl];
[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];
NSData *videoData;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *pdfPath=[documentsDir stringByAppendingFormat:@"/video.mp4"];
NSLog(@"%@",pdfPath);
if ([[NSFileManager defaultManager] fileExistsAtPath:pdfPath])
{
NSLog(@"exist");
videoData = [NSData dataWithContentsOfFile:pdfPath];
}
if (videoData)
{
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *temp=[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video\"; filename=\"video.mp4\"\r\n"];
[body appendData:[[NSString stringWithString:temp] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"temp %@",temp);
[body appendData:[@"Content-Type: video/mp4\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:videoData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}else
{
NSLog(@"NOT Data");
}
videoData=nil;
[request setHTTPBody:body];
NSLog(@"logoooooooo---q-%@",request);
NSLog(@"URLTwo Vedio==> %@?action=%@&userId=%@&postId=%@",urlstring,LAction,appDelegate.userId,stringReturnXmlOne);
con = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
if (con)
{
self.receivedData = [[NSMutableData alloc]init];
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
NSLog(@"RECIEVED DATA Video %@",self.receivedData);
}
else
{
[activityIndicator stopAnimating];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error connecting to remote server" delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
NSLog(@"Finish Video");
}https://stackoverflow.com/questions/5629430
复制相似问题