Created
March 12, 2010 08:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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