[8946] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | // edit with personal settings
|
---|
[8986] | 4 | $location = ' ';
|
---|
| 5 | $username = ' ';
|
---|
| 6 | $password = ' ';
|
---|
| 7 | $database = ' ';
|
---|
[8946] | 8 |
|
---|
[8986] | 9 | $filelist = array();
|
---|
| 10 | $filelist = scandir("csv");
|
---|
| 11 | sort($filelist);
|
---|
| 12 | unset($filelist[0]);
|
---|
| 13 | unset($filelist[1]);
|
---|
| 14 | unset($filelist[2]);
|
---|
[8968] | 15 |
|
---|
[8986] | 16 |
|
---|
[8968] | 17 | // connect to database
|
---|
| 18 | mysql_connect($location, $username, $password)
|
---|
| 19 | or die("Error connecting to mysql: " . mysql_error());
|
---|
| 20 | mysql_select_db($database)
|
---|
| 21 | or die("Error connecting to database: " . mysql_error());
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 |
|
---|
[8986] | 25 | foreach($filelist as $file) {
|
---|
| 26 |
|
---|
| 27 | $table = substr($file, 0, -4);
|
---|
| 28 |
|
---|
| 29 | // create table
|
---|
| 30 | mysql_query("
|
---|
| 31 | CREATE TABLE IF NOT EXISTS ".$table." (
|
---|
| 32 | latitude double(9,7) NOT NULL,
|
---|
| 33 | longitude double(9,7) NOT NULL,
|
---|
| 34 | ssid varchar(45) NOT NULL,
|
---|
| 35 | mac varchar(45) NOT NULL,
|
---|
| 36 | encryption tinyint(4) NOT NULL,
|
---|
| 37 | ID int(11) NOT NULL AUTO_INCREMENT,
|
---|
| 38 | PRIMARY KEY (ID)
|
---|
| 39 | )
|
---|
| 40 | ");
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | // .csv file to open
|
---|
| 44 | if (($handle = fopen("csv/".$file, "r")) !== FALSE) {
|
---|
| 45 | while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
|
---|
| 46 | $lat=str_replace("N ", "", $data[0]);
|
---|
| 47 | $lon=str_replace("E ", "", $data[1]);
|
---|
| 48 | $enc = substr($data[8], -2, 1);
|
---|
| 49 | echo "\"".$lat.", ".$lon."\", \"".$data[2]."\", \"".$data[4]."\", \"".$enc."\"<br />\n";
|
---|
| 50 | $query=mysql_query("INSERT INTO ".$table." (latitude, longitude, ssid, mac, encryption) VALUES ('$lat','$lon','$data[2]','$data[4]','$enc')");
|
---|
| 51 | if (!$query) {
|
---|
| 52 | die('Invalid query: ' . mysql_error());
|
---|
| 53 | }
|
---|
[8946] | 54 | }
|
---|
[8986] | 55 | fclose($handle);
|
---|
| 56 | rename("csv/".$file, "csv/backup/".$file);
|
---|
[8946] | 57 | }
|
---|
[8986] | 58 |
|
---|
[8946] | 59 | }
|
---|
| 60 |
|
---|
| 61 | ?>
|
---|