I have spent hours reading about how to upload large files to a server. These video files will be in the hundreds of megabytes, and will be in .mp4 format.
My first attempt was using PHP processing a POST, but this was not working with files above two megabytes due to the restrictions in php.ini and httpd.conf.
Some users were simply increasing these limits to the levels they needed, and hoping the upload would work.
Some websites seem to be using flash uploaders, but the ones I have tried have been difficult, and never explicitly mentioned if they solved the upload size problem.
I have also looked at FTP using PHP as a client, but all the examples I found were simply transferring the file to an FTP server after it had been POSTed. FTP using a separate client is out of the question, as the file name and related data is stored in a database.
Currently, I am operating on localhost, and the site will be served from a box I have physical access t开发者_Python百科o, but I am still wary of increasing the max_upload_size and related requirements because eventually I want to move to a hosted service.
What would be the best solution? Is there a way to do upload large files strictly through PHP and HTML? If not, what is the best solution to upload large files while still being able to pass the filename to a database?
Thanks to all who answer
The standard form-based file upload doesn’t work for you since files are uploaded in a single HTTP POST requests.
- Web servers cannot normally accept large HTTP requests.
- The upload process is long. If there is a connection problem, the user has to start over.
If you are looking for a solution built into the website, you should consider using some upload component which can shrink files to chunks client-side, send each chunk in a separate request and put together files on server. These components work as browser extensions. Even though everybody is obsessed with HTML5 these days and nobody likes Java applets and ActiveX components, Java/ActiveX suits best for your task.
I think that programming something using PHP will always end in the limitations of and HTTP file upload. I would use an app like Simple2FTP instead of trying to program something that is viable in PHP. http://www.simple2ftp.com uses a PHP script to handle users and manage files and JavaScript to do the actual upload via FTP.
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");
}
try to upload the file manually using http request as bytes. and as you control both sides (Client and Server). you can pass the full file name in the headers.
精彩评论