From b465f67969b721b9bad2a8cc7cf4337f926f9ad2 Mon Sep 17 00:00:00 2001 From: qnnp Date: Tue, 16 Jan 2024 20:20:55 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=A8=20phar=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=A4=9A=E4=B8=AA=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8=E6=AD=A4=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E8=83=BD=E4=BC=9A=E9=80=A0=E6=88=90=E7=9A=84?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CaptchaBuilder.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CaptchaBuilder.php b/src/CaptchaBuilder.php index c92f0e1..de941f1 100644 --- a/src/CaptchaBuilder.php +++ b/src/CaptchaBuilder.php @@ -501,18 +501,24 @@ public function build($width = 150, $height = 40, $font = null, $fingerprint = n * @param $font * @return string */ - protected function getFontPath($font) + protected function getFontPath($font, $prefix = 0) { static $fontPathMap = []; if (!\class_exists(\Phar::class, false) || !\Phar::running()) { return $font; } + $fileName = ($prefix ? "$prefix-" : '') . basename($font); $tmpPath = sys_get_temp_dir() ?: '/tmp'; - $filePath = "$tmpPath/" . basename($font); + $filePath = "$tmpPath/" . $fileName; clearstatcache(); - if (!isset($fontPathMap[$font]) || !is_file($filePath)) { + if (!is_file($filePath)) { file_put_contents($filePath, file_get_contents($font)); + } + if (!is_readable($filePath)){ + return $this->getFontPath($font, $prefix+1); + } + if (!isset($fontPathMap[$font]) ) { $fontPathMap[$font] = $filePath; } return $fontPathMap[$font]; From 927083833d870fd4c137211759a427784da0fe4a Mon Sep 17 00:00:00 2001 From: qnnp Date: Thu, 28 Mar 2024 12:32:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"=E4=BC=98=E5=8C=96=E5=9C=A8=20pha?= =?UTF-8?q?r=20=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=A4=9A=E4=B8=AA=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8=E6=AD=A4=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=97=B6=E5=8F=AF=E8=83=BD=E4=BC=9A=E9=80=A0=E6=88=90?= =?UTF-8?q?=E7=9A=84=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b465f67969b721b9bad2a8cc7cf4337f926f9ad2. --- src/CaptchaBuilder.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/CaptchaBuilder.php b/src/CaptchaBuilder.php index de941f1..c92f0e1 100644 --- a/src/CaptchaBuilder.php +++ b/src/CaptchaBuilder.php @@ -501,24 +501,18 @@ public function build($width = 150, $height = 40, $font = null, $fingerprint = n * @param $font * @return string */ - protected function getFontPath($font, $prefix = 0) + protected function getFontPath($font) { static $fontPathMap = []; if (!\class_exists(\Phar::class, false) || !\Phar::running()) { return $font; } - $fileName = ($prefix ? "$prefix-" : '') . basename($font); $tmpPath = sys_get_temp_dir() ?: '/tmp'; - $filePath = "$tmpPath/" . $fileName; + $filePath = "$tmpPath/" . basename($font); clearstatcache(); - if (!is_file($filePath)) { + if (!isset($fontPathMap[$font]) || !is_file($filePath)) { file_put_contents($filePath, file_get_contents($font)); - } - if (!is_readable($filePath)){ - return $this->getFontPath($font, $prefix+1); - } - if (!isset($fontPathMap[$font]) ) { $fontPathMap[$font] = $filePath; } return $fontPathMap[$font]; From f5adb973290dcf727327bc33dc630dabe9ab64f6 Mon Sep 17 00:00:00 2001 From: qnnp Date: Thu, 28 Mar 2024 15:07:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=A8=20phar=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=A4=9A=E4=B8=AA=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8=E6=AD=A4=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E8=83=BD=E4=BC=9A=E9=80=A0=E6=88=90=E7=9A=84?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CaptchaBuilder.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CaptchaBuilder.php b/src/CaptchaBuilder.php index c92f0e1..65490aa 100644 --- a/src/CaptchaBuilder.php +++ b/src/CaptchaBuilder.php @@ -509,6 +509,12 @@ protected function getFontPath($font) } $tmpPath = sys_get_temp_dir() ?: '/tmp'; + if (function_exists('runtime_path')) { + $tmpPath = runtime_path('tmp'); + if (!is_dir($tmpPath)) { + mkdir($tmpPath, 0777, true); + } + } $filePath = "$tmpPath/" . basename($font); clearstatcache(); if (!isset($fontPathMap[$font]) || !is_file($filePath)) {