Skip to content

Commit 460ae25

Browse files
author
Bradie Tilley
committed
Fix issue where REMOTE_ADDR server variable is not set when running through CLI
1 parent 50e65d4 commit 460ae25

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

classes/Resizer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ public function setImage(string $image = null, bool $doNotModifyPath = false)
129129
}
130130

131131
// Check if the image is an absolute url to the same server, if so get the storage path of the image
132-
$regex = '/^(?:https?:\/\/)?' . $_SERVER['SERVER_NAME'] . '(?::\d+)?\/(.+)$/';
133-
if (preg_match($regex, $image, $m)) {
134-
// Convert spaces, not going to urldecode as it will mess with pluses
135-
$image = base_path(str_replace('%20', ' ', $m[1]));
136-
$absolutePath = true;
132+
if (!empty($_SERVER['SERVER_NAME'])) {
133+
$regex = '/^(?:https?:\/\/)?' . $_SERVER['SERVER_NAME'] . '(?::\d+)?\/(.+)$/';
134+
if (preg_match($regex, $image, $m)) {
135+
// Convert spaces, not going to urldecode as it will mess with pluses
136+
$image = base_path(str_replace('%20', ' ', $m[1]));
137+
$absolutePath = true;
138+
}
137139
}
138140

139141
// If not an absolute path, set it to an absolute path

updates/version.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@
4545
- Improvement to the detection of the original image's mime type (uses less system resources)
4646
2.2.0:
4747
- Added optional permalinks for images to ensure image URLs always yield the same image after cache flushes
48-
- create_permalinks_table.php
48+
- create_permalinks_table.php
49+
2.2.1:
50+
- Fix issue where REMOTE_ADDR server variable is not set when running through CLI

0 commit comments

Comments
 (0)