From 58da6ec7c289a0454ec33c4d1e16cf83b0b2af38 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 24 Oct 2022 20:55:32 +0800 Subject: [PATCH] bug fix: pathinfo() return empty when the filename is chinese --- lib/DirScanner.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 2eb6ddf..3df339b 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -87,8 +87,9 @@ Class DirScanner { //解析描述文件内容 //snapshot相对路径完善,支持secure_link private function parseDescriptionFiles($realpath) { + $filename = $this->getFilenameWithoutExtension($realpath); $pathinfo = pathinfo($realpath); - $tmp = explode('_', $pathinfo['filename']); + $tmp = explode('_', $filename); $field = array_pop($tmp); $content = @file_get_contents($realpath); if (empty($content)) {return [];} @@ -103,9 +104,10 @@ Class DirScanner { $fp = fopen($img_realpath, 'r'); $fstat = fstat($fp); fclose($fp); + $img_filename = $this->getFilenameWithoutExtension($img_realpath); $img_pathinfo = pathinfo($img_realpath); $extension = strtolower($img_pathinfo['extension']); - $content = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_pathinfo['filename'], $extension, $fstat['mtime'] ); + $content = $this->getFilePath( $id, $this->getRelativeDirname($img_pathinfo['dirname']), $img_filename, $extension, $fstat['mtime'] ); } } } @@ -169,6 +171,11 @@ Class DirScanner { return array_pop($arr); } + //获取文件名,不含文件后缀 + private function getFilenameWithoutExtension($realpath) { + return preg_replace('/\.[a-z]+$/i', '', $this->basename($realpath)); + } + //根据路径生成目录数组 private function getDirData($realpath, $files) { $id = $this->getId($realpath); @@ -215,9 +222,10 @@ Class DirScanner { fclose($fp); $pathinfo = pathinfo($realpath); $extension = strtolower($pathinfo['extension']); + $filename = $this->getFilenameWithoutExtension($realpath); $data = array( 'id' => $id, - 'filename' => $pathinfo['filename'], + 'filename' => $filename, 'extension' => $extension, 'fstat' => array( 'size' => $fstat['size'], @@ -226,11 +234,11 @@ Class DirScanner { 'ctime' => $fstat['ctime'], ), 'realpath' => $this->isApi ? $this->getRelativeDirname($realpath) : $realpath, - 'path' => $this->getFilePath( $id, $this->getRelativeDirname($pathinfo['dirname']), $pathinfo['filename'], $extension, $fstat['mtime'] ), + 'path' => $this->getFilePath( $id, $this->getRelativeDirname($pathinfo['dirname']), $filename, $extension, $fstat['mtime'] ), ); if ($extension == 'url') { - $data['shortcut'] = $this->parseShortCuts($realpath, $pathinfo['filename']); + $data['shortcut'] = $this->parseShortCuts($realpath, $filename); } return $data; @@ -692,10 +700,11 @@ Class DirScanner { $fp = fopen($src_realpath, 'r'); $fstat = fstat($fp); fclose($fp); + $src_filename = $this->getFilenameWithoutExtension($src_realpath); $src_pathinfo = pathinfo($src_realpath); $extension = strtolower($src_pathinfo['extension']); - $src_path = $this->getFilePath( $id, $this->getRelativeDirname($src_pathinfo['dirname']), $src_pathinfo['filename'], $extension, $fstat['mtime'] ); + $src_path = $this->getFilePath( $id, $this->getRelativeDirname($src_pathinfo['dirname']), $src_filename, $extension, $fstat['mtime'] ); $html = str_replace("\"{$url}\"", "\"{$src_path}\"", $html); }