123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\common\model;
- class FileManageModel
- {
-
- public static function getRootDir()
- {
- return Templet::getRootDir();
- }
-
- public static function getFileList($name = "", $relativePath = "")
- {
-
- $rootpath = self::getRootDir() . DS . $relativePath;
- $files = [];
- if (!file_exists($rootpath)) {
- return $files;
- }
-
- $handle = opendir($rootpath);
- while (false !== ($f = readdir($handle))) {
-
- if ($f == "." || $f == "..") {
- continue;
- }
-
- $filepath = rtrim($rootpath, DS) . DS . $f;
-
- $filename = $f;
-
- if (isset($name) and !empty($name)) {
- if (!ifContain($filename, $name)) {
- continue;
- }
- }
- $info = pathinfo($filepath);
- $ext = $info['extension']??'';
- $filename = str_replace_once("." . $ext, "", $filename);
- $key = filetype($filepath) . '-' . $ext . '-' . $filename;
- $files[$key] = [
- "filename" => $filename,
- "fileext" => $ext,
- "filetype" => filetype($filepath),
- "filesize" => filesize($filepath),
- "fileatime" => date('Y-m-d H:i:s', fileatime($filepath)),
- "filectime" => date('Y-m-d H:i:s', filectime($filepath)),
- "filemtime" => date('Y-m-d H:i:s', filemtime($filepath)),
- ];
- }
-
- ksort($files);
-
- $data = [];
- foreach ($files as $k => $v) {
- $data[] = $v;
- }
- return $data;
- }
- }
|