/
Inventory.php
86 lines (77 loc) · 1.78 KB
/
Inventory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
==============================================================
Inventory - by Joshua R Jones
for The General Metrics Web Development Company
http://general-metrics.com
Copyright (c) 2009 The General Metrics Web Development Company
==============================================================
*/
function inventory_list($source_dir)
{
// Open the dir and set the vars
$root = opendir($source_dir);
$output = array();
while($file = readdir($root))
{
if($file != ".." && $file[0] != '.' && $file != "Inventory")
{
//If file is a subdirectory, pop inside
if(is_dir($file))
{
// Loop through the subdirectory
$filestore = array();
$filestore["dir"] = $file;
$store = array();
$store["files"] = inventory_list($source_dir . '/' . $file);
$filestore = array_merge($filestore, $store);
$output[] = $filestore;
}
else
{
// Find and spit out only the HTML files
if(preg_match('/(.*).html/', $file))
{
$output[] = array("filename" => $file);
}
}
}
}
closedir($root);
rsort($output);
return $output;
}
$inv = inventory_list(".");
//print_r($inv);
// JSON output
$json = json_encode($inv);
$jsonarr = '({"filelist": ';
$jsonarr .= $json;
$jsonarr .= '})';
$response = $_GET['callback'] . $jsonarr;
echo $response;
// End of Inventory.php
$fixture = array(
array(
"dir" => "",
"files" => array(
"index.html",
"test.html"
)
),
array(
"dir" => "tmp_dir1",
"files" => array(
"dir_1_test1.html",
"dir_1_test2.html"
)
)
);
// $testjson = json_encode($fixture);
// $jsonarr2 = "<br>";
// $jsonarr2 .= '({"filelist": ';
// $jsonarr2 .= $testjson;
// $jsonarr2 .= '})';
//
// $response2 = $_GET['callback'] . $jsonarr2;
// echo $response2;