Location: PHPKode > projects > Geo GPS > geoGPS.v1.0/geonames.php
<?php
# Geonames load script
// Download countries: http://download.geonames.org/export/dump/

// Place the XX.txt files in the same folder as this script, and open this in your browser. 
// Just click on the countries you want to import to your geo_names table

include_once('overall.php'); //find the overall.php file (should be in the root of geo)
$db = mysql_connect(GEO_DB_HOST,GEO_DB_USER,GEO_DB_PASS);
mysql_select_db(GEO_DB_NAME,$db);	

if ($gd = @opendir('./')) {
	while (($ar = @readdir($gd)) !== false) {
		if(preg_match("/[A-Z]{2}\.txt/",$ar)) {
			$pts = explode('.',$ar);
			echo '<a href="?ct='.$pts[0].'">'.$pts[0].'</a> ';
		}
	}
	closedir($gd);
} else {
	die("Unable to open this folder");
}
echo '<hr>';
echo '<p style="font-size: 1px; letter-space: 0;">';
$fi = $_GET['ct'];
if(preg_match("/[A-Z]{2}/",$fi)) {
	$gestor = @fopen("$fi.txt", "r");
	if ($gestor) {
	    while (!feof($gestor)) {
		$line = fgets($gestor, 4096);
		if(!empty($line)) {
			$tab = explode("\t",$line);
			if(empty($tab[15])) $tab[15] = 0;
			$qry = "INSERT INTO geo_names VALUES ($tab[0],'".str_replace("'",'`',$tab[1])."','$tab[6]','$tab[7]','$tab[8]',$tab[4],$tab[5],$tab[15])";
			if(!mysql_query($qry)) {
				//mysql_query("TRUNCATE TABLE geonames");
				die("</p>FAILED!! <br><hr> $qry<br><br>".mysql_error());
			}
			//echo "$qry <br>\n";
			echo '* ';
		}
		
	    }
	    fclose ($gestor);
	} else echo 'Resource not opened';
}
echo '</p>';
echo '<p>.END.</p>';

// Using the Haversine formula to find closest places. Replace LAT & LNG in the sentence.
// SELECT (6371*acos(cos(radians(LAT))*cos(radians(lat))*cos(radians(lng)-radians(LNG))+sin(radians(LAT))*sin(radians(lat)))) AS distance FROM geo_names ORDER BY distance ASC
Return current item: Geo GPS