From 1411bce1dc13bf6fea66b5899ba29d50d5c53bb0 Mon Sep 17 00:00:00 2001 From: pantsucat Date: Thu, 17 Sep 2015 23:12:51 +1000 Subject: Add html response class --- static/classes/Response.class.php | 23 +++++++++++++++++++++++ static/upload.php | 7 ++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/static/classes/Response.class.php b/static/classes/Response.class.php index 25121ce..9c22a30 100755 --- a/static/classes/Response.class.php +++ b/static/classes/Response.class.php @@ -12,6 +12,10 @@ class Response header('Content-Type: text/plain; charset=UTF-8'); $this->type = $response_type; break; + case 'html': + header('Content-Type: text/html;charset=utf-8'); + $this->type = 'html'; + break; default: header('Content-Type: application/json; charset=UTF-8'); $this->type = 'json'; @@ -30,6 +34,9 @@ class Response case 'gyazo': $response = $this->gyazo_error($code, $desc); break; + case 'html': + $response = $this->html_error($code, $desc); + break; default: $response = $this->json_error($code, $desc); break; @@ -44,6 +51,9 @@ class Response $response = null; switch ($this->type) { + case 'html': + $response = $this->html_success($files); + break; case 'csv': $response = $this->csv_success($files); break; @@ -86,6 +96,19 @@ class Response { return POMF_URL.$files[0]['url']; } + private static function html_error($code, $description) + { + return 'ERROR: ('.$code.') '.$description; + } + + private static function html_success($files) + { + foreach ($files as $file) { + $result .= "".$file['url']."
"; + } + + return $result; + } private static function json_error($code, $description) { diff --git a/static/upload.php b/static/upload.php index 4dc45a3..21ae386 100644 --- a/static/upload.php +++ b/static/upload.php @@ -93,7 +93,6 @@ function upload_file($file) $result = $q->fetch(); if ($result['count'] > 0) { unlink($file->tempfile); - return array( 'hash' => $file->get_sha1(), 'name' => $file->name, @@ -132,11 +131,10 @@ function upload_file($file) $q->bindValue(':exp', null, PDO::PARAM_STR); $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR); $q->execute(); - return array( 'hash' => $file->get_sha1(), 'name' => $file->name, - 'url' => POMF_URL.$newname, + 'url' => $newname, 'size' => $file->size, ); } else { @@ -196,6 +194,7 @@ function refiles($files) } $type = isset($_GET['output']) ? $_GET['output'] : 'json'; + $response = new Response($type); if (isset($_FILES['files'])) { @@ -212,3 +211,5 @@ if (isset($_FILES['files'])) { } else { $response->error(400, 'No input file(s)'); } + + -- cgit v1.2.3