简单小巧的js文件浏览器
XML/HTML Code
- <div class="filemanager">
- <div class="search">
- <input type="search" placeholder="Find a file.." />
- </div>
- <div class="breadcrumbs"></div>
- <ul class="data"></ul>
- <div class="nothingfound">
- <div class="nofiles"></div>
- <span>No files here.</span>
- </div>
- </div>
php文件
PHP Code
- <?php
- $dir = "files";
- // Run the recursive function
- $response = scan($dir);
- // This function scans the files folder recursively, and builds a large array
- function scan($dir){
- $files = array();
- // 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[] = array(
- "name" => $f,
- "type" => "folder",
- "path" => $dir . '/' . $f,
- "items" => scan($dir . '/' . $f) // Recursively get the contents of the folder
- );
- }
- else {
- // It is a file
- $files[] = array(
- "name" => $f,
- "type" => "file",
- "path" => $dir . '/' . $f,
- "size" => filesize($dir . '/' . $f) // Gets the size of this file
- );
- }
- }
- }
- return $files;
- }
- // Output the directory listing as JSON
- header('Content-type: application/json');
- echo json_encode(array(
- "name" => "files",
- "type" => "folder",
- "path" => $dir,
- "items" => $response
- ));
原文地址:http://www.freejs.net/article_jquerywenzi_591.html