123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * Created by PhpStorm.
- * User: 中闽 < 1464674022@qq.com >
- * Date: 2019/12/5
- * Time: 17:44
- */
- namespace app\common\model;
- class FileManageModel
- {
- /**
- * 文件管理根目录
- * @return string
- */
- public static function getRootDir()
- {
- return Templet::getRootDir();
- }
- /**
- * 获取所有文件信息
- * @param string $name [过滤文件名]
- * @param string $relativePath [过滤子目录]
- * @return array
- */
- 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 = iconv("gb2312", "utf-8", $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),//文件or文件夹
- "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);
- //重置索引为数字,否則layui表格全选不支持勾选
- $data = [];
- foreach ($files as $k => $v) {
- $data[] = $v;
- }
- return $data;
- }
- }
|