summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2014-07-23 16:15:16 +0100
committerLuke Bratch <l_bratch@yahoo.co.uk>2014-07-23 16:15:16 +0100
commit7b6ceda54dd6f6b49d439447f925474b01fbd6a3 (patch)
tree4842d21e2044ee5f89c15c4ac689468822cf4028
parent428d38c8be1086bbeabe9affed63b0b4c03bb288 (diff)
Separate presentation from list generation and add options for HTML or
JSON output
-rw-r--r--index.php86
1 files changed, 54 insertions, 32 deletions
diff --git a/index.php b/index.php
index b8a98fa..7b6a1a9 100644
--- a/index.php
+++ b/index.php
@@ -67,18 +67,6 @@ function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f
}
?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-<title>Index of /</title>
-</head>
-<body>
-
-<form action="upload_file.php" method="post"
-enctype="multipart/form-data">
-<input type="file" name="file" id="file"> <input type="submit" name="submit" value="Submit">
-</form>
-
<?php
$nameurl = "?C=N;O=A";
$modifiedurl = "?C=M;O=A";
@@ -106,12 +94,11 @@ if (isset($_GET['C'])) {
}
}
-
+$listing = array();
+$listing[0] = array();
?>
-
-<pre><img src="/icons/blank.gif" alt="Icon "> <a href="<?php echo $nameurl; ?>">Name</a> <a href="<?php echo $modifiedurl; ?>">Last modified</a> <a href="<?php echo $sizeurl; ?>">Size</a><hr><?php
-
+<?php
date_default_timezone_set("GB");
#print_r(listdir_by_date("./"));
@@ -146,24 +133,16 @@ if (isset($sort)) {
krsort($new_array);
}
+$listsize = 0;
+
while ($this_array = each($new_array)){
$value = $this_array['value'];
$key = $this_array['key'];
- $key_convert = date("d-M-Y H:i", $key);
- if (strlen($value) > 23) {
- $preview = substr($value, 0, 20) . "..>";
- } else {
- $preview = $value;
- }
- $spaces = "";
- for ($i = 0; $i < (24 - strlen($preview)); $i++) {
- $spaces = $spaces . " ";
- }
-
-$fileparts = explode('.', strtolower($value));
-$icon = "unknown";
-switch ($fileparts[count($fileparts)-1]) {
+ $fileparts = explode('.', strtolower($value));
+ $icon = "unknown";
+
+ switch ($fileparts[count($fileparts)-1]) {
case "png":
case "jpg":
case "gif":
@@ -256,14 +235,57 @@ switch ($fileparts[count($fileparts)-1]) {
default:
$icon="unknown";
break;
-}
+ }
- echo '<img src="/icons/'.$icon.'.gif" alt="[IMG]"> <a href="' . $value . '">' . $preview . '</a>' . $spaces . $key_convert . ' ' . size_readable($size_array[$key], null, "bi") . ' ' . "\n";
+ $listing[$listsize]['filename'] = $value;
+ $listing[$listsize]['type'] = $icon;
+ $listing[$listsize]['modified'] = $key;
+ $listing[$listsize]['size'] = $size_array[$key];
+
+
+ $listsize++;
}
clearstatcache();
+
+if (!isset($_GET['format']) || $_GET['format'] == "html") {
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<title>Index of /</title>
+</head>
+<body>
+
+<form action="upload_file.php" method="post"
+enctype="multipart/form-data">
+<input type="file" name="file" id="file"> <input type="submit" name="submit" value="Submit">
+</form>
+
+<pre><img src="/icons/blank.gif" alt="Icon "> <a href="<?php echo $nameurl; ?>">Name</a> <a href="<?php echo $modifiedurl; ?>">Last modified</a> <a href="<?php echo $sizeurl; ?>">Size</a>
+<hr><?php
+for ($i = 0; $i < count($listing); $i++) {
+ if (strlen($listing[$i]['filename']) > 23) {
+ $preview = substr($listing[$i]['filename'], 0, 20) . "..>";
+ } else {
+ $preview = $listing[$i]['filename'];
+ }
+
+ $spaces = "";
+
+ for ($j = 0; $j < (24 - strlen($preview)); $j++) {
+ $spaces = $spaces . " ";
+ }
+
+ echo '<img src="/icons/' . $listing[$i]['type'] . '.gif" alt="[IMG]"> <a href="' . $listing[$i]['filename'] . '">' . $preview . '</a>' . $spaces . date("d-M-Y H:i", $listing[$i]['modified']) . ' ' . size_readable($listing[$i]['size'], null, "bi") . ' ' . "\n";
+}
?>
<hr></pre>
<address>Apache Server at www.blaupload.co.uk Port 80</address>
</body></html>
+<?php
+} else if ($_GET['format'] == "json") {
+ echo json_encode($listing);
+}
+?>