01 <?php
02 $orgFile = 'VirtualBox.exe';
03 $cacheFileName = 'vbcache';
04
05
06 cutFile($orgFile, 10 * pow(2,20)); //10 * pow(2,20) 就等于 10M
07 mergeFile('cache2vb.exe');
08
09 function cutFile($fileName,$block) {
10 global $cacheFileName;
11
12 if (!file_exists($fileName)) return false;
13
14 $num = 1;
15 $file = fopen($fileName, 'rb');
16 while ($content = fread($file,$block)) {
17 $cacheFile = $cacheFileName . $num++ . '.dat';
18 $cfile = fopen($cacheFile, 'wb');
19 fwrite($cfile, $content);
20 fclose($cfile);
21 }
22 fclose($file);
23 }
24
25 function mergeFile($targetFile) {
26 global $cacheFileName;
27
28 $num = 1;
29 $file = fopen($targetFile, 'wb');
30 while ($num > 0) {
31 $cacheFile = $cacheFileName . $num++ . '.dat';
32 if (file_exists($cacheFile)) {
33 $cfile = fopen($cacheFile, 'rb');
34 $content = fread($cfile, filesize($cacheFile));
35 fclose($cfile);
36 fwrite($file, $content);
37 } else {
38 $num = -1;
39 }
40 }
41 fclose($file);
42 }