One of the known limitations of free hosting packages is the file upload limit. For example, some hosting companies set an upload limit of 500 KB. This means that for any uploads to the FTP server, the file should not be more than 500 KB or else the server won’t accept it and you will not be able to upload your file. Fortunately, by splitting your files, you can get around this limitation; this two-part tutorial series will show you how.
The first step is to show a web form that accepts the file name to be split and the maximum file upload limit size in kilobytes. The second step should be to receive the POST data and compute the number of splitting parts. (The complete script will be downloaded/shown in the second part of this tutorial)
The formula for the number of parts into which the file will be split is:
Number of Split Parts (PHP variable: $parts_num) = (File size / Maximum Upload limit) x 2
The script uses a safety factor of two to make sure the resulting file size of the split parts is significantly less than the maximum upload limit of the FTP server. So for example, say the file size to be split is 1.1 MB and the FTP server maximum upload size is 500KB. The number of split parts can be computed like this:
Number of Split Parts (PHP variable: $parts_num) = ((1100KB) / (500KB)) x 2 = 4.4, rounding down to implement a realistic value brings us to four parts.
Since 1.1MB cannot be uploaded at once using a 500 KB upload limit, with four parts the file size per upload will be reduced to 1100KB/4 ~ 275KB, which is less than 500KB, but you have to upload each of the parts to the FTP server.
In PHP the file size can be measured by:
$filesize = ((filesize($file_name))/1000);
Using the filesize() function gives the results in bytes, so to convert that to kilobytes, divide the equation by 1000.
Rounding down can be accomplished by a floor() PHP function, so for example to implement rounding down of the number of parts:
$parts_num = floor($parts_num);
Then the split file function (PHP user-defined function splitthisfile()) accepts two inputs, $file_name and $parts_num. A modification script was formulated based on Arash Hemmat's original PHP class.