Skip to content

Commit

Permalink
Revert "优化在 phar 模式下多个系统同时使用此组件时可能会造成的临时文件权限问题"
Browse files Browse the repository at this point in the history
This reverts commit b465f67.
  • Loading branch information
qnnp committed Mar 28, 2024
1 parent b465f67 commit 9270838
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/CaptchaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 9270838

Please sign in to comment.