1 <?php
2 
3 if(!defined('GeoLite2_DIR')) define('GeoLite2_DIR', realpath(dirname(__FILE__) ) . '/'); //  '/GeoLite2-City/');
4 echo GeoLite2_DIR . "\n";  exit;
5 global $City_dnld_dir;
6 function listdir($start_dir='.', $found=false) {
7    global $City_dnld_dir;
8 
9   if (is_dir($start_dir)) {
10     $fh = opendir($start_dir);
11     while (($file = readdir($fh)) !== false) {
12       # loop through the files, skipping . and .., and recursing if necessary
13       if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
14       $filepath = $start_dir . '/' . $file;
15       if ( is_dir($filepath) ) {
16           if($found) {
17              $found = false;
18               return;
19           }
20           if(preg_match('/GeoLite2-City_*\d+/',$filepath)) {
21               $found = true;
22               $City_dnld_dir = $filepath;
23               echo "Directory: $filepath \nFiles:\n";
24           }
25            listdir($filepath,$found);
26         }
27         else if($found  && preg_match('/GeoLite2-City_*\d+/',$filepath)) {
28             if(preg_match("/GeoLite2-City.mmdb/",$filepath)) {
29                    unlink("./GeoLite2-City/GeoLite2-City.mmdb");
30                   copy ($filepath , "./GeoLite2-City/GeoLite2-City.mmdb") ;
31             }
32             echo "unlinking: $filepath \n";
33             unlink($filepath);
34           }
35           else if($found) {
36               echo "returning\n";
37               return;
38           }
39     }
40     closedir($fh);
41   } else {
42       return false;
43       # false if the function was called with an invalid non-directory argument
44 
45   }
46 
47   return true;
48 
49 }
50 
51 
52 listdir('.');
53 echo   $City_dnld_dir ."\n";
54 rmdir($City_dnld_dir);
55 
56 ?>
57