Browse Source

bug fix: pathinfo() return empty when the filename is chinese

master
filesite 2 years ago
parent
commit
58da6ec7c2
  1. 21
      lib/DirScanner.php

21
lib/DirScanner.php

@ -87,8 +87,9 @@ Class DirScanner {
//解析描述文件内容 //解析描述文件内容
//snapshot相对路径完善,支持secure_link //snapshot相对路径完善,支持secure_link
private function parseDescriptionFiles($realpath) { private function parseDescriptionFiles($realpath) {
$filename = $this->getFilenameWithoutExtension($realpath);
$pathinfo = pathinfo($realpath); $pathinfo = pathinfo($realpath);
$tmp = explode('_', $pathinfo['filename']); $tmp = explode('_', $filename);
$field = array_pop($tmp); $field = array_pop($tmp);
$content = @file_get_contents($realpath); $content = @file_get_contents($realpath);
if (empty($content)) {return [];} if (empty($content)) {return [];}
@ -103,9 +104,10 @@ Class DirScanner {
$fp = fopen($img_realpath, 'r'); $fp = fopen($img_realpath, 'r');
$fstat = fstat($fp); $fstat = fstat($fp);
fclose($fp); fclose($fp);
$img_filename = $this->getFilenameWithoutExtension($img_realpath);
$img_pathinfo = pathinfo($img_realpath); $img_pathinfo = pathinfo($img_realpath);
$extension = strtolower($img_pathinfo['extension']); $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); return array_pop($arr);
} }
//获取文件名,不含文件后缀
private function getFilenameWithoutExtension($realpath) {
return preg_replace('/\.[a-z]+$/i', '', $this->basename($realpath));
}
//根据路径生成目录数组 //根据路径生成目录数组
private function getDirData($realpath, $files) { private function getDirData($realpath, $files) {
$id = $this->getId($realpath); $id = $this->getId($realpath);
@ -215,9 +222,10 @@ Class DirScanner {
fclose($fp); fclose($fp);
$pathinfo = pathinfo($realpath); $pathinfo = pathinfo($realpath);
$extension = strtolower($pathinfo['extension']); $extension = strtolower($pathinfo['extension']);
$filename = $this->getFilenameWithoutExtension($realpath);
$data = array( $data = array(
'id' => $id, 'id' => $id,
'filename' => $pathinfo['filename'], 'filename' => $filename,
'extension' => $extension, 'extension' => $extension,
'fstat' => array( 'fstat' => array(
'size' => $fstat['size'], 'size' => $fstat['size'],
@ -226,11 +234,11 @@ Class DirScanner {
'ctime' => $fstat['ctime'], 'ctime' => $fstat['ctime'],
), ),
'realpath' => $this->isApi ? $this->getRelativeDirname($realpath) : $realpath, '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') { if ($extension == 'url') {
$data['shortcut'] = $this->parseShortCuts($realpath, $pathinfo['filename']); $data['shortcut'] = $this->parseShortCuts($realpath, $filename);
} }
return $data; return $data;
@ -692,10 +700,11 @@ Class DirScanner {
$fp = fopen($src_realpath, 'r'); $fp = fopen($src_realpath, 'r');
$fstat = fstat($fp); $fstat = fstat($fp);
fclose($fp); fclose($fp);
$src_filename = $this->getFilenameWithoutExtension($src_realpath);
$src_pathinfo = pathinfo($src_realpath); $src_pathinfo = pathinfo($src_realpath);
$extension = strtolower($src_pathinfo['extension']); $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); $html = str_replace("\"{$url}\"", "\"{$src_path}\"", $html);
} }

Loading…
Cancel
Save