// ====================== 【自动读取学校环境图片】一行4张 ====================== $school_name = $row['title']; $school_classid = $classid; if ($school_classid == 35) { $type_dir = '复读学校'; } elseif ($school_classid == 49) { $type_dir = '学校官网'; } else { $type_dir = '其他学校'; } $base_img_dir = __DIR__ . '/学校图片/'; $school_img_dir = $base_img_dir . $type_dir . '/' . $school_name . '/'; $img_list = []; $allowed_ext = ['jpg','jpeg','png','gif','webp']; if (is_dir($school_img_dir)) { $files = scandir($school_img_dir); foreach ($files as $file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (!in_array($ext, $allowed_ext) || $file == '.' || $file == '..') continue; $web_path = '/学校图片/' . $type_dir . '/' . $school_name . '/' . $file; // ====================== 终极硬切:最后一个 / 后面,. 前面 ====================== $show_name = basename($web_path); // 得到: 宿舍.jpg $show_name = preg_replace('/\..+$/', '', $show_name); // 硬切掉后缀 → 宿舍 // ============================================================================ $img_list[] = [ 'path' => $web_path, 'name' => $show_name, 'alt' => $show_name ]; } }