Php resumable upload: how to split merged files

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
Ini_set ("memory_limit", "50 M"); // required. Try to avoid errors based on the actual environment conditions.
Ini_set ("maid", "100 ");
// The file_exists () function checks whether a file or directory exists. If yes, true is returned. Otherwise, false is returned.
// Fread () function reads files (which can be safely used for binary files ). Fread () reads a maximum of length bytes from the file pointer.
// The filesize () function returns the size (in bytes) of the specified object ). The result of this function is cached. Use clearstatcache () to clear the cache.
$ OrgFile = 'Fireworks8-chs.exe '; // source file
$ CacheFileName = 'vbcache'; // 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, 10 * pow (); // 10 * pow () is equal to 10 M pow () function returns x to the power of y
MergeFile(' OK .exe ');
?>

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.