您可以使用ftell()自行调查 . 文件指针的当前位置是文件基础结构的固有部分,PHP只是在libc / glibc的fopen / fread / etc实现之上 .
但是,考虑一下:
$fh = fopen('somefile.txt', 'r');
文件指针现在将是零位置,因为没有读取数据 .
$data = fread($fh, 500);
文件指针现在将位于位置500,因为它作为前一个fread调用的一部分读取位置0-> 499(500字节) .
$data = fread($fh, 0); // makes no sense to read 0 bytes, but hey...
仍然在500位
$data = fread($fh, 1); // now at 501
$data = fread($fh, 2); // now at 503
等等...
基本上,使用ftell()来检查自己 . ftell()用于检索文件指针的CURRENT位置,因此您可以使用记住您所在的位置 . 然后你可以使用rewind(),fseek()等......将指针全部移动,然后向右跳回你原来的地方而不会丢失:
$old_loc = ftell($fh); // 503
fseek($fh, 9999);
fseek($fh, 20000); // jump around a bit
fseek($fh, $old_loc); // back to 503, ready to resume reading where we left off.