首页 > Other > php文件分割组合源代码

php文件分割组合源代码

<?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);
}

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: