Skip to content

Instantly share code, notes, and snippets.

@wilhelm-murdoch
Created March 12, 2010 08:15
Show Gist options
  • Save wilhelm-murdoch/330149 to your computer and use it in GitHub Desktop.
Save wilhelm-murdoch/330149 to your computer and use it in GitHub Desktop.
Does a binary-safe split of a specified file. The number of chunks generated is determined by the $chunks parameter.
function chunkFile($file, $chunks = 2)
{
$handle = fopen($file, 'rb');
$count = 1;
while(false == feof($handle))
{
if($data = fread($handle, round(filesize($file) / $chunks)))
{
file_put_contents(basename($file) . "-chunk-{$count}.txt", $data);
$count++;
}
}
fclose($handle);
return $count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment