From 28d9c654389b7b2a3e9c79c9369181f1b7c3da81 Mon Sep 17 00:00:00 2001
From: Peter Wu
Date: Mon, 31 Mar 2014 17:52:05 +0200
Subject: tmp-upload: do not output HTML for wget or curl
---
tmp-upload | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/tmp-upload b/tmp-upload
index e72f98f..52fe039 100755
--- a/tmp-upload
+++ b/tmp-upload
@@ -41,6 +41,10 @@ function get_mime_type($file) {
$url = urldecode($_SERVER['REQUEST_URI']);
+/* treat non-browser programs specially, do not output HTML for them */
+$userAgent = explode("/", filter_input(INPUT_SERVER, "HTTP_USER_AGENT"))[0];
+$text_only = in_array($userAgent, array("curl", "Wget"));
+
/* Simply returning false causes PHP to parse (index).php. Unwanted,
* therefore serve it here. First check whether the path is within the
* current working directory, then whether the file exists or not. */
@@ -100,6 +104,7 @@ if (is_dir($path)) {
$msg = "";
if (isset($_FILES["file"]["name"]) && is_array($_FILES["file"]["name"])) {
+ // file[] array upload
$upload = $_FILES["file"];
for ($i=0; $i
@@ -149,7 +168,9 @@ function saveUpload($upload) {
$msg