使用了应用商店下的PHP,提示没有GLOB_BRACE常量


各位技术人员们,我想请教以下问题:
我在1Panel中搭建了一个网站,使用的是PHP8.2.15(在应用商店中安装的),我使用过了其中的8.1、8.0、7.4等版本测试,均为显示不支持GLOB_BRACE这个常量,这个常量按理说是8.2都已经支持了的

我使用的是以下php代码,用途是随机使用某个文件夹下的图片作为背景,我个人电脑环境下是可以正常使用这个常量,之前在某塔的编译的PHP下使用也正常,不知是哪方面的原因,还想请教一下
目前是使用了其他类似的方法替换了这个常量

function getRandomBackground() {
    $folderPath = './images/background/';
    $images = glob($folderPath . '*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
    return $images[array_rand($images)];
}

if (empty($_POST["user"]) || empty($_POST["pass"]) || empty($_POST["verify"])) {
    include "login_page.php";
    echo '<style>body { background-image: url("' . getRandomBackground() . '"); }</style>';
} else {.....

1Panel版本:v1.10.2-lts
浏览器版本:chrome目前最新版

The GLOB_BRACE flag is not available on some non GNU systems, like Solaris or Alpine Linux.

貌似是因为1panel的php镜像是php:xxx-fpm-alpine
另外想问一下你现在是咋解决的

1 个赞

重新构建了php的docker镜像解决问题,dockerfile如下

FROM    php:7.4.33-fpm-bullseye
MAINTAINER      Fisher "N"

# 设置时区
ENV TZ=Asia/Shanghai

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
ADD sources.list /opt/1panel/runtime/php/hkcms/php/sources.list
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && mkdir /opt/web && mkdir -p /usr/local/php74/var/log && touch /usr/local/php74/var/log/php-fpm.log && touch /usr/local/php74/var/log/php_errors.log \
    && groupadd www -g 1000 && useradd -s /sbin/nologin -M www -u 1000 -g 1000 && mkdir /home/www && chown www:www /home/www \
    && chown www:www /usr/local/php74/var/log/php-fpm.log /usr/local/php74/var/log/php_errors.log \   
    && DEBIAN_FRONTEND=noninteractive apt-get update -q \
    && DEBIAN_FRONTEND=noninteractive apt-get install -qq -y \
      curl \
      git  \
      zip unzip \
    && install-php-extensions \
      @composer-2.5.8 \
      gd \
      mysqli \
      pdo_mysql \
    && docker-php-ext-enable \
      gd \
      mysqli \
      pdo_mysql \

多谢解答
我就改这样了,效果差不多:class BackgroundImage {
public function getRandomBackground(): string {
$folderPath = ‘./images/background/’;
$allowedExtensions = array(‘jpg’, ‘jpeg’, ‘png’, ‘gif’, ‘webp’);
$images = array();

    $files = scandir($folderPath);
    foreach ($files as $file) {
        // 检查文件扩展名是否在允许的范围内
        $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
        if (in_array($extension, $allowedExtensions)) {
            $images[] = $file;
        }
    }
    return $folderPath . $images[array_rand($images)];
}

}

非常感谢

你好,我也遇到这个问题了,这个是先在面板的镜像里新建DockerFile,然后再去容器里把网站的PHP镜像切换成这个吗?
ERROR: ld.so: object ‘/usr/lib/preloadable_libiconv.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘php’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘/usr/lib/preloadable_libiconv.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘php’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
[03-May-2024 05:35:19] NOTICE: fpm is running, pid 1
[03-May-2024 05:35:19] NOTICE: ready to handle connections

你好,我也遇到这个问题了,这个是先在面板的镜像里新建DockerFile,然后再去容器里把网站的PHP镜像切换成这个吗?
ERROR: ld.so: object ‘/usr/lib/preloadable_libiconv.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘php’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘/usr/lib/preloadable_libiconv.so’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object ‘php’ from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
[03-May-2024 05:35:19] NOTICE: fpm is running, pid 1
[03-May-2024 05:35:19] NOTICE: ready to handle connections