vastant.blogg.se

Upload txt to ip2location
Upload txt to ip2location













upload txt to ip2location
  1. #Upload txt to ip2location how to#
  2. #Upload txt to ip2location install#
  3. #Upload txt to ip2location driver#
  4. #Upload txt to ip2location code#

perform query and return a single result filter those ip_to which are greater than our IP number select a collection (analogous to a relational database's table) Save the buildindexipv4 and then run the following in command prompt: mongo -u mongoAdmin -p changeMe -authenticationDatabase admin ip2location

#Upload txt to ip2location code#

Next, create a text file called buildindexipv4 and paste the following code into it: use ip2location Create index to speed up queries For Linux Same with the CSV file folder mine is C:\inetpub\wwwroot\TestMongoPHP\ so remember to change to the folder where you have extracted the CSV file earlier. My MongoDB is installed in C:\mongodb but if your installation folder is different, remember to change the example above. For WindowsĪt the command prompt, run the following command: C:\mongodb\bin\mongoimport -u mongoAdmin -p changeMe -authenticationDatabase admin -drop -db ip2location -collection db25 -type csv -file "C:\inetpub\wwwroot\TestMongoPHP\IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.CSV" -fields ip_from,ip_to,country_code,country_name,region_name,city_name,latitude,longitude,zip_code,time_zone,isp,domain,net_speed,idd_code,area_code,weather_station_code,weather_station_name,mcc,mnc,mobile_brand,elevation,usage_type,address_type,category My CSV file folder is /var/www/TestMongoPHP while your folder may be different so remember to change to the folder where you have extracted the CSV file earlier. Importing the CSV data into MongoDB For LinuxĪt the command prompt, run the following command: mongoimport -u mongoAdmin -p changeMe -authenticationDatabase admin -drop -db ip2location -collection db25 -type csv -file "/var/www/TestMongoPHP/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.CSV" -fields ip_from,ip_to,country_code,country_name,region_name,city_name,latitude,longitude,zip_code,time_zone,isp,domain,net_speed,idd_code,area_code,weather_station_code,weather_station_name,mcc,mnc,mobile_brand,elevation,usage_type,address_type,category NOTE: Make sure you run the above command in the folder where your PHP page is going to be created.

#Upload txt to ip2location install#

To install the MongoDB PHP Library, you will need to have the PHP composer for either Linux or Windows then run the following command.

#Upload txt to ip2location driver#

Windows users can get the driver from and then edit the php.ini to load the dll.

upload txt to ip2location

pecl install mongodbĮcho "extension=mongodb.so" > `php -ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` To install the MongoDB PHP driver, Linux users can run the following commands in Bash. use admin ĭb.grantRolesToUser("mongoAdmin", ) Pre-requisites To grant the necessary permission, run the following in the mongo client. Please note that this is a requirement since we will drop the existing database and collection during import.

upload txt to ip2location

This user has been granted the privilege to drop databases. For our example, our MongoDB has a user called mongoAdmin with changeMe as the password. We will assume you have already setup MongoDB and are using PHP via Apache on a Linux or Windows platform.

upload txt to ip2location

We will not cover installation of either MongoDB or PHP in this guide.

#Upload txt to ip2location how to#

The aim of this guide is to demonstrate how to import IP2Location data (DB25) in CSV form into MongoDB and then query the data in a PHP web page.įirst of all, you will need to download the IP2Location DB25 CSV file.Įxtract out the IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE-ADDRESSTYPE-CATEGORY.CSV file from the downloaded zipped file.















Upload txt to ip2location