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...