uploading files over 2gb with php and apache

i recently ran into a problem at work where i was implementing a php-based file upload system. we wanted the end users to be able to upload files larger than 2 gigabtyes in size. (whether or not allowing gigs of upload over http is the best choice, this was the desire.)
the first issue is that many browsers themselves can not handle uploading files over 2gb in size. recent versions of safari, chrome, and opera can – so far firefox and internet explorer can not. if you’re trying to use firefox or ie, it ain’t gonna happen even if php can handle it.
unfortunately, even if you’re browser can handle it, php isn’t coded to be able to — there are some int/long issues in the php code. (i only messed with 5.2.x, not 5.3.x.) even if you’re on a 64-bit system and have a version of php compiled with 64-bit, there are several problem areas.
first, the code that converts post_max_size and others from ascii (#K/#M/#G shorthand) to integer stores the resulting value in an int, so when it converts “9G” (for example) and puts the result into this int it will bork the value because 9G in bytes is a larger number than a 32-bit variable can hold.
at first i just made this change, because someone had said that’s all you need to do. but i don’t think they were using apache or the php apache code. with just this change you don’t see some of the obtuse/weird errors you’d see pre-change, but what’ll happen is you’ll see (from the server side) the temp file increasing in size — then when it hits 2gb it will just disappear. the browser will dutifully continue to upload the file until it’s done, but the file won’t be on the server.
so if you’re using apache as your web server, there are some other things you need to change — several other areas of php code used with the apache module, cgi, etc. that need to be changed from int to long.
so…for this to work, you need to edit the php code and compile it by hand (make sure you compile it as 64-bit). here’s a link to a list of diffs:
(referenced from this php bug post)
the file above is a diff on 5.2.10 code, but i made the changes by hand to 5.2.17 code and i have uploaded 3.4gb single files through apache/php (which hadn’t worked before the change).