Hi there, I had a quick question of sorts.
I was looking at this tutorial(http://tutorialzine.com/2014/09/cute-fi ... -ajax-php/), and thought it would be a good fit for a site I'm creating. The site has a resources section, with folders, sub-folders and eventually files to download (using dynamic folders).
The php file in the tutorial is designed to scan the folder structure, and replicate it.
I was wondering if someone with a better grasp of listing folders and files in couch would have an idea of how to replace this code, with something listing all the dynamic folders and files using couch?
I only had a very quick go at it, but I just couldn't get my head round what was required to list the folders and their contents in a way that would work with this format.
No worries if no-one can be bothered, I realise it's a bit cheeky to come on here without giving it a serious go, but I doubt I could do it, and someone might have done something similar!
Cheers!
I was looking at this tutorial(http://tutorialzine.com/2014/09/cute-fi ... -ajax-php/), and thought it would be a good fit for a site I'm creating. The site has a resources section, with folders, sub-folders and eventually files to download (using dynamic folders).
The php file in the tutorial is designed to scan the folder structure, and replicate it.
I was wondering if someone with a better grasp of listing folders and files in couch would have an idea of how to replace this code, with something listing all the dynamic folders and files using couch?
- Code: Select all
<?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
));
I only had a very quick go at it, but I just couldn't get my head round what was required to list the folders and their contents in a way that would work with this format.
No worries if no-one can be bothered, I realise it's a bit cheeky to come on here without giving it a serious go, but I doubt I could do it, and someone might have done something similar!
Cheers!