Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // emulate large fseek($fp, $pos, SEEK_SET) on 32-bit system
- // requires bcmath
- function emulated_fseek($fp, $pos) {
- if(bccomp((string)PHP_INT_MAX, $pos, 0) > -1) // small, do it natively
- fseek($fp, (int)$pos, SEEK_SET);
- else {
- fseek($fp, PHP_INT_MAX, SEEK_SET);
- fread($fp, 1); // get past fseek limitation
- $pos = bcsub(bcsub($pos, (string)PHP_INT_MAX), 1);
- $chunk = 8192-1; // get around weird 8KB limitation
- while($pos) {
- if(bccomp((string)$chunk, $pos, 0) > -1) {
- fseek($fp, (int)$pos, SEEK_CUR);
- break;
- }
- else {
- fseek($fp, $chunk, SEEK_CUR);
- fread($fp, 1);
- $pos = bcsub($pos, (string)($chunk+1));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement