Skip to content

Commit 65669f0

Browse files
authored
Merge branch 'master' into feature/PLUG-5386
2 parents 7e795ba + fcdcf9c commit 65669f0

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

includes/classes/PPMFWC/Gateway/Abstract.php

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,40 +108,45 @@ public function saveLogo(string $imagePath): bool
108108
*/
109109
public function downloadImage(string $url, string $basePath, string $image): bool
110110
{
111-
$image = ltrim($image, '/');
111+
try {
112+
$image = ltrim($image, '/');
112113

113-
if (str_contains($image, '..')) {
114-
return false;
115-
}
116-
if (!preg_match('~^[a-zA-Z0-9/_\.\-]+$~', $image)) {
117-
return false;
118-
}
114+
if (str_contains($image, '..')) {
115+
return false;
116+
}
117+
118+
if (!preg_match('~^[a-zA-Z0-9/_\.\-]+$~', $image)) {
119+
return false;
120+
}
119121

120-
// Alleen bekende image-extensies toestaan
121-
if (!preg_match('~\.(svg|png|jpe?g|webp)$~i', $image)) {
122-
return false;
123-
}
122+
// Alleen bekende image-extensies toestaan
123+
if (!preg_match('~\.(svg|png|jpe?g|webp)$~i', $image)) {
124+
return false;
125+
}
124126

125-
// Download (404 e.d. geeft geen warning)
126-
$data = @file_get_contents($url);
127-
if ($data === false) {
128-
return false;
129-
}
127+
// Download (404 e.d. geeft geen warning)
128+
$data = @file_get_contents($url);
129+
if ($data === false) {
130+
return false;
131+
}
132+
133+
$fullPath = rtrim($basePath, '/') . '/' . $image;
130134

135+
$dir = dirname($fullPath);
136+
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
137+
return false;
138+
}
131139

132-
$fullPath = rtrim($basePath, '/') . '/' . $image;
140+
$writeResult = false;
141+
if (is_writable(dirname($fullPath))) {
142+
$writeResult = file_put_contents($fullPath, $data) !== false;
143+
}
133144

134-
$dir = dirname($fullPath);
135-
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
145+
return $writeResult;
146+
} catch (\Throwable $t) {
147+
PPMFWC_Helper_Data::ppmfwc_payLogger('Error downloading image: ' . $t->getMessage(), null, null, 'error');
136148
return false;
137149
}
138-
139-
$writeResult = false;
140-
if (is_writable(dirname($fullPath))) {
141-
$writeResult = file_put_contents($fullPath, $data) !== false;
142-
}
143-
144-
return $writeResult;
145150
}
146151

147152

0 commit comments

Comments
 (0)