Home > Backend Development > PHP Tutorial > How to split and merge files in PHP breakpoint resume_PHP tutorial

How to split and merge files in PHP breakpoint resume_PHP tutorial

WBOY
Release: 2016-07-13 10:35:16
Original
1054 people have browsed it

Copy code The code is as follows:

ini_set("memory_limit", "50M");//required Yes, try to make it as large as possible according to the actual situation of your environment to prevent errors
ini_set("max_execution_time", "100");
//file_exists() function checks whether the file or directory exists, returns true if it exists, otherwise returns false.
//fread() function reads files (safe for binary files). fread() reads up to length bytes from the file pointer file.
//filesize() function returns the size (bytes) of the specified file. The results of this function will be cached. Please use clearstatcache() to clear the cache.
$orgFile = 'Fireworks8-chs.exe';//Source file
$cacheFileName = 'vbcache';//Split into temporary file blocks
function cutFile($fileName,$block) {/ /split
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) {//Merge
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);
}
//Call
cutFile($orgFile, 10 * pow(2,20)); //10 * pow(2,20) It is equal to 10M. The pow() function returns x raised to the yth power
mergeFile('ok.exe');
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/744708.htmlTechArticleCopy the code code as follows: ?php ini_set("memory_limit", "50M");//Required, according to The actual situation of your environment should be as large as possible to prevent errors ini_set("max_execution_time", "100"); //file_exi...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template