Skip to content

Commit fd1879e

Browse files
committed
Fixed BIN Downloader Script with .env file
1 parent bdbdb8b commit fd1879e

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ You can also sign up for [IP2Location Web Service](https://www.ip2location.com/w
118118

119119
## BIN DOWNLOADER SCRIPT
120120
```
121-
php ip2location_bin_download.php --token DOWNLOAD_TOKEN --file DATABASE_CODE
121+
php ip2location_bin_download.php --token DOWNLOAD_TOKEN --file DATABASE_CODE -y
122122
```
123123

124124
The command above will download the DATABASE_CODE BIN file and unzip the file into *data* folder.
@@ -127,8 +127,9 @@ The command above will download the DATABASE_CODE BIN file and unzip the file in
127127
|---|---|
128128
|token|Download token. You can get your token at your [IP2Location Account Area](https://www.ip2location.com/account) at the Download page.|
129129
|file|Database package. (DB1BIN...DB26BIN, DB1BINIPV6...DB26BINIPV6, DB1LITEBIN...DB11LITEBIN or DB1LITEBINIPV6...DB11LITEBINIPV6) You may login to your [IP2Location Account Area](https://www.ip2location.com/account) and get the package code (or download code) at the Download page. |
130+
|y|Auto replace the current BIN file without acknowledgement.|
130131

131-
You can set the **DOWNLOAD_TOKEN** and **DATABASE_CODE** with values in the .env file and run the command `php ip2location_bin_download.php` for the download.
132+
You can set the **DOWNLOAD_TOKEN** and **DATABASE_CODE** with values in the .env file (same path as *ip2location_bin_download.php*) and run the command `php ip2location_bin_download.php` for the download.
132133

133134
## IPv4 BIN vs IPv6 BIN
134135
* Use the IPv4 BIN file if you just need to query IPv4 addresses.

ip2location_bin_download.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
define('DBTEMP', ROOT . 'dbtemp' . DS);
1616

1717

18-
$shortOpt = "";
18+
$shortOpt = "y";
1919
$longOpt = ["token:", "file:"];
2020
$inputs = getopt($shortOpt, $longOpt);
2121

2222
$token = '';
2323
$dbCode = '';
24+
$passReplace = false;
2425
$fileName = '';
2526
$fileNameDwld = '';
2627
$fileSize = 0;
@@ -33,6 +34,10 @@
3334
$dbCode = $inputs["file"];
3435
}
3536

37+
if(isset($inputs["y"])) {
38+
$passReplace = true;
39+
}
40+
3641
$envFilePath = realpath(ROOT . ".env");
3742
$varArr = [];
3843
if (is_file($envFilePath)) {
@@ -379,7 +384,11 @@
379384
}
380385

381386
if ($fileName != '') {
382-
$action = readline('The ' . substr($fileName, 0, -4) . ' file inside the data folder will be replaced. Would you like to proceed? (y/n): ');
387+
if ($passReplace) {
388+
$action = 'y';
389+
} else {
390+
$action = readline('The ' . substr($fileName, 0, -4) . ' file inside the data folder will be replaced. Would you like to proceed? (y/n): ');
391+
}
383392
} else {
384393
echo "[Error] Unknown --file command line parameter.\n";
385394
exit;
@@ -454,7 +463,7 @@
454463
rmdir(DBTEMP);
455464
unlink($fileName);
456465

457-
echo "[Success] The " . substr($fileName, 0, -4) . " file has been successfully downloaded into data folder.\n";
466+
echo "[Success] The " . substr($fileName, 0, -4) . " file has been successfully downloaded into the data folder.\n";
458467
} else {
459468
exit;
460469
}

src/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Database
1212
*
1313
* @var string
1414
*/
15-
public const VERSION = '9.6.0';
15+
public const VERSION = '9.6.1';
1616

1717
/**
1818
* Unsupported field message.

0 commit comments

Comments
 (0)