-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFIleList.php
58 lines (55 loc) · 1.64 KB
/
getFIleList.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
<?php
require("config.inc.php");
$isCached =false;
$folder = __FOLDERS_ROOT__;
$apcukey = "";
$useDB = false;
if(isset($_REQUEST["cached"]))
$isCached = ($_REQUEST["cached"] == "yes");
if(isset($_REQUEST["apcukey"]))
$apcuKey = $_REQUEST["apcukey"];
if(isset($_REQUEST["folder"]))
$folder .= $_REQUEST["folder"];
if(isset($_REQUEST["usedb"]))
$useDB = ($_REQUEST["usedb"] == "yes");
if ($useDB){
$mysqli = new mysqli("localhost", __DB_USER__, __DB_PASSWORD__, __DB_NAME__);
if ($isCached){
if (!apcu_exists($apcuKey)){
$result = $mysqli->query("SELECT imageid FROM images;");
apcu_add($apcuKey,json_encode($result->fetch_all()),86400);
}
echo (apcu_fetch($apcuKey));
}
else{
$result = $mysqli->query("SELECT imageid FROM images;");
echo(json_encode($result->fetch_all()));
}
$mysqli->close();
}
else{
if ($isCached){
if (!apcu_exists($apcuKey)){
$iFiles = new DirectoryIterator("$folder");
$response = "";
while ($file = $iFiles->getFileName()) {
if (!is_dir($file))
$response .= $file.";";
$iFiles->next();
}
apcu_add($apcuKey,$response,86400);
}
echo (apcu_fetch($apcuKey));
}
else{
$iFiles = new DirectoryIterator($folder);
$response = "";
while ($file = $iFiles->getFileName()) {
if ($file!="." && $file!="..")
$response .= $file.";";
$iFiles->next();
}
echo($response);
}
}
?>