2012-11-05 47 views
1

不知道我做了什么错误,但是这个错误让我很生气。我不断收到“FSEEK():提供的参数是不是一个有效的流资源”从下面这些代码错误: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

什么'的var_dump($这个 - >文件句柄,函数get_resource_type($这个 - >文件句柄))之前搜索的问题;'输出,如果你的'FSEEK之前正确的地方它() '打电话? – nickb

+0

它给了我NULL。我试着明确地把这段代码放在顶部,但仍然给出了相同的错误。 $ this-> filehandle ='/absolute-path/GeoLiteCity.dat'; – user1576748

+0

'$ this-> filehandle'不能是字符串或文件名,它需要是一个资源。 – nickb

回答

0

尝试检查资源$ GI->文件句柄。但我认为你必须将此代码

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); 
} 
相关问题