donglou1866 2012-07-03 10:40
浏览 46
已采纳

PHP LimitIterator失败(“不支持搜索”+“无法回放文件”)

I use SplFileObject and LimitIterator to read content from position x till y of a big file.

This works perfectly when using a file path like /home/devel/stuff/myfile.log.

When using a path like http://mydomain.com:8090/devel/stuff/myfile.log it does not work. The path is correct however.

Does this fail when using absolute paths?


The error messages are:

PHP Warning: SplFileObject::rewind() [<a href='splfileobject.rewind'>splfileobject.rewind</a>]: stream does not support seeking in ...

PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot rewind file ...'


Full code:

  // $pStrFile contains the valid (yes!) path
  $oFile = new SplFileObject($pStrFile);
  // $nFrom = 80 and $nLines = 30
  $fileIterator = new LimitIterator($oFile, $nFrom, $nLines);

  foreach($fileIterator as $line) {
      $strLines .= $line;
  }
  • 写回答

2条回答 默认 最新

  • doumanni3501 2012-07-03 10:43
    关注

    This is a limitation of the http wrapper. If a file is on the disk, you can access it on any position. If you want to start reading in the middle of the file, that is possible. However, when the file is on a webserver and you get it with HTTP, it is a little bit harder to read the middle of the file.

    You can copy the file to a temporary location and then use the LimitIterator on it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?