Php resumable Upload: how to split and merge files _ PHP Tutorial

Source: Internet
Author: User
Php resumable Upload: how to split and merge files. Copy the code as follows :? Phpini_set (memory_limit, 50 M); required. it should be as big as possible based on the actual situation of your environment to prevent ini_set (max_execution_time, 100); file_exi The code is as follows:


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

The http://www.bkjia.com/PHPjc/744708.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/744708.htmlTechArticle code is as follows :? Php ini_set ("memory_limit", "50 M"); // required. it should be as big as possible based on the actual situation of your environment to prevent ini_set ("max_execution_time", "100 "); // file_exi...

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.