不确定我做错了什么,但这个错误让我很生气。我一直得到“fseek():提供的参数不是一个有效的流资源”错误来自下面这些代码:
public function _geoip_seek_country($ipnum) {
$offset = 0;
for ($depth = 31; $depth >= 0; $depth--) {
if ($this->flags & $this->GEOIP_MEMORY_CACHE) {
$enc = mb_internal_encoding();
mb_internal_encoding('ISO-8859-1');
$buf = substr($this->memory_buffer,
2 * $this->record_length * $offset,
2 * $this->record_length);
mb_internal_encoding($enc);
} elseif ($this->flags & $this->GEOIP_SHARED_MEMORY) {
$buf = @shmop_read ($this->shmid,
2 * $this->record_length * $offset,
2 * $this->record_length );
} else {
fseek($this->filehandle, 2 * $this->record_length * $offset, SEEK_SET) == 0
or die("fseek failed");
$buf = fread($this->filehandle, 2 * $this->record_length);
}
$x = array(0,0);
for ($i = 0; $i < 2; ++$i) {
for ($j = 0; $j < $this->record_length; ++$j) {
$x[$i] += ord($buf[$this->record_length * $i + $j]) << ($j * 8);
}
}
if ($ipnum & (1 << $depth)) {
if ($x[1] >= $this->databaseSegments) {
return $x[1];
}
$offset = $x[1];
} else {
if ($x[0] >= $this->databaseSegments) {
return $x[0];
}
$offset = $x[0];
}
}
trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR);
return false;
}
该文件确实存在并将权限设置为777.
$this->filehandle = fopen($filename,"rb"))
已经是真的。不知道为什么一直说
提供的参数不是有效的流资源
答案 0 :(得分:0)
尝试检查资源的$ gi-&gt;文件句柄。但我认为你必须在此代码之前搜索问题
if (is_resource($gi->filehandle)) {
fseek($this->filehandle, 2 * $this->record_length * $offset, SEEK_SET) == 0 or die("fseek failed");
$buf = fread($this->filehandle, 2 * $this->record_length);
}