PHP breakpoint Continuation How to split merge files _php tutorial

Source: Internet
Author: User
Tags fread pow
Copy CodeThe code is as follows:
Ini_set ("Memory_limit", "50M");//must, according to the actual situation of your environment as large as possible to prevent errors
Ini_set ("Max_execution_time", "100");
The file_exists () function checks whether a file or directory exists, returns True if it exists, or false otherwise.
The Fread () function reads the file (which can be used safely in binary files). Fread () reads up to length bytes from file pointer files.
The FileSize () function returns the size (in bytes) of the specified file. The result of this function is cached. Please use Clearstatcache () to clear the cache.
$orgFile = ' fireworks8-chs.exe ';//source file
$cacheFileName = ' vbcache ';//split into a temporary file block
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, ten * POW (2,20)); Ten * POW (2,20) equals the 10M Pow () function returns the Y-order of X
Mergefile (' Ok.exe ');
?>

http://www.bkjia.com/PHPjc/744708.html www.bkjia.com true http://www.bkjia.com/PHPjc/744708.html techarticle Copy the code as follows: Php ini_set ("Memory_limit", "50M"),//must, according to the actual situation of your environment as large as possible to prevent error Ini_set ("Max_execution_time", "100"); File_exi ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.