Search code examples
maxmindgeoip2geolite2

The file GeoLite2-Country.mmdb does not exist or is not readable


I am in a little project where I need to collect the country form people who submit a contact form to one site, now I'm using MaxMind/GeoLite2 reading the DB file with GeoIp2 v2.0 (installed from composer) and I am getting the next error message.

The file GeoLite2-Country.mmdb does not exist or is not readable.

I am using CodeIgniter v3.1.6

This is the full error message:

An uncaught Exception was encountered
Type: InvalidArgumentException

Message: The file "http://localhost/isite/assets/geoip2db/GeoLite2-Country.mmdb" does not exist or is not readable.

Filename: C:\xampp\htdocs\isite\vendor\maxmind-db\reader\src\MaxMind\Db\Reader.php

Line Number: 48

Backtrace:

File: C:\xampp\htdocs\isite\vendor\geoip2\geoip2\src\Database\Reader.php
Line: 53
Function: __construct

File: C:\xampp\htdocs\isite\application\controllers\Main.php
Line: 28
Function: __construct

File: C:\xampp\htdocs\isite\index.php
Line: 317
Function: require_once

The GeoLite2-Country.mmdb file is there.

Here is the function where I call the GeoIp2 Class:

public function contact_submit(){
$reader = new GeoIp2\Database\Reader(base_url().'assets/geoip2db/GeoLite2-Country.mmdb');
$record = $reader->country($_SERVER['REMOTE_ADDR']);
$data = array(
    'name' => $this->input->post('name'),
    'mail' => $this->input->post('mail'),
    'phone' => $this->input->post('phone'),
    'comment' => $this->input->post('comment'),
    'USER_AGENT' => $_SERVER['HTTP_USER_AGENT'],
    'ADDR' => $_SERVER['REMOTE_ADDR'],
    'PORT' => $_SERVER['REMOTE_PORT'],
    'ISO' => $record->country->isoCode,
    'COUNTRY_NAME' => $record->country->name,
    'COUNTRY_STATE' => $record->mostSpecificSubdivision->name,
    'COUNTRY_STATE_ISO' => $record->mostSpecificSubdivision->isoCode,
    'CITY_NAME' => $record->city->
    'POSTAL_CODE' => $record->postal->code,
    'LONGITUDE' => $record->location->longitude,
    'LATITUDE' => $record->location->latitude
);
if($this->MainModel->submitComment($data))
    redirect(base_url().'index.php/main/contact?statusMessage=1', 'location');
else
    redirect(base_url().'index.php/main/contact?statusMessage=0', 'location');
}

If more info is needed please leave a comment and I will add it as soon as posible


Solution

  • The constructor takes a path to a local database file but you appear to be providing it with an HTTP URI. You need to remove or replace base_url().