summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2014-09-21 12:20:11 +0100
committerLuke Bratch <l_bratch@yahoo.co.uk>2014-09-21 12:20:11 +0100
commit7ffc77710590d6b9dec685aa94160b10e7dcb0d8 (patch)
tree7727d41f3b729cf5bde77ff8c31cf2a5f3b81ac2
parentfb9545e2f59cfa551a3951a8afcb9d3659db522f (diff)
Provide example upload form and submission files
-rw-r--r--upload.html4
-rw-r--r--upload_file.php64
2 files changed, 68 insertions, 0 deletions
diff --git a/upload.html b/upload.html
new file mode 100644
index 0000000..cdc49a1
--- /dev/null
+++ b/upload.html
@@ -0,0 +1,4 @@
+<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>
+Different formats: <a href="?format=plain">Plain text</a>, <a href="?format=light">lightweight</a> or <a href="?format=json">JSON</a>! Specify <a href="?from=2014-05-01&amp;to=2014-06-01"> date ranges</a>! Only show the <a href="?last=10">last X files</a>! Ranges work with any format.
diff --git a/upload_file.php b/upload_file.php
new file mode 100644
index 0000000..09f2bd7
--- /dev/null
+++ b/upload_file.php
@@ -0,0 +1,64 @@
+<?php include('config.php'); ?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Upload result</title>
+</head>
+<body>
+<p>
+<?php
+function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s') {
+ // Pick units
+ $systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
+ $systems['si']['size'] = 1000;
+ $systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
+ $systems['bi']['size'] = 1024;
+ $sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];
+
+ // Max unit to display
+ $depth = count($sys['prefix']) - 1;
+ if ($max && false !== $d = array_search($max, $sys['prefix'])) {
+ $depth = $d;
+ }
+
+ // Loop
+ $i = 0;
+ while ($size >= $sys['size'] && $i < $depth) {
+ $size /= $sys['size'];
+ $i++;
+ }
+
+ return sprintf($retstring, $size, $sys['prefix'][$i]);
+}
+
+ {
+ if ($_FILES["file"]["error"] > 0)
+ {
+ echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
+ }
+ else
+ {
+ if (file_exists($_FILES["file"]["name"]))
+ {
+ echo "Error: " . $_FILES["file"]["name"] . " already exists. ";
+ }
+ else
+ {
+ move_uploaded_file($_FILES["file"]["tmp_name"],
+ "./" . $_FILES["file"]["name"]);
+ echo "Uploaded: " . $_FILES["file"]["name"] . "<br>";
+ $fileurl = "$url" . $_FILES["file"]["name"];
+ echo "URL: <a href=\"$fileurl\">$fileurl</a><br>";
+ echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi");
+ }
+ }
+ }
+?>
+</p>
+<p>
+<a href="<?php echo $url; ?>">Back to index</a>
+</p>
+</body>
+</html>