<?php
$orgFile = 'VirtualBox.exe';
$cacheFileName = 'vbcache';

cutFile($orgFile, 10 * pow(2,20)); //10 * pow(2,20) 就等于 10M 
mergeFile('cache2vb.exe');

function cutFile($fileName,$block) {
    global $cacheFileName;
    if (!file_exists($fileName)) return false;
    $num    = 1;    
    $file   = fopen($fileName, 'rb');
    while ($content = fread($file,$block)) {
        $cacheFile = $cacheFileName . $num++ . '.dat';
        $cfile = fopen($cacheFile, 'wb');
        fwrite($cfile, $content);
        fclose($cfile);
    }
    fclose($file);
}

function mergeFile($targetFile) {
    global $cacheFileName;
    $num = 1;
    $file = fopen($targetFile, 'wb');
    while ($num > 0) {
        $cacheFile = $cacheFileName . $num++ . '.dat';
        if (file_exists($cacheFile)) {
            $cfile = fopen($cacheFile, 'rb');
            $content = fread($cfile, filesize($cacheFile));
            fclose($cfile);
            fwrite($file, $content);
        } else {
            $num = -1;
        }
    }
    fclose($file);    
}