1 Star 0 Fork 104

linxs / VvvebJs

forked from Gitee 极速下载 / VvvebJs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
scan.php 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
givanz 提交于 2021-05-29 22:16 . Media gallery plugin for image input
<?php
$scandir = __DIR__ . '/media/';
// Run the recursive function
// This function scans the files folder recursively, and builds a large array
$scan = function ($dir) use ($scandir, &$scan) {
$files = [];
// Is there actually such a folder/file?
if (file_exists($dir)) {
foreach (scandir($dir) as $f) {
if (! $f || $f[0] == '.') {
continue; // Ignore hidden files
}
if (is_dir($dir . '/' . $f)) {
// The path is a folder
$files[] = [
'name' => $f,
'type' => 'folder',
'path' => str_replace($scandir, '', $dir) . '/' . $f,
'items' => $scan($dir . '/' . $f), // Recursively get the contents of the folder
];
} else {
// It is a file
$files[] = [
'name' => $f,
'type' => 'file',
'path' => str_replace($scandir, '', $dir) . '/' . $f,
'size' => filesize($dir . '/' . $f), // Gets the size of this file
];
}
}
}
return $files;
};
$response = $scan($scandir);
// Output the directory listing as JSON
header('Content-type: application/json');
echo json_encode([
'name' => '',
'type' => 'folder',
'path' => '',
'items' => $response,
]);
JavaScript
1
https://gitee.com/linxs007/VvvebJs.git
git@gitee.com:linxs007/VvvebJs.git
linxs007
VvvebJs
VvvebJs
master

搜索帮助