From 2dafdedfe29aee7ed19d141bbe0953e94b4a499b Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sun, 22 Nov 2015 21:56:53 +0000 Subject: Various code cleanups --- index.php | 24 ++++++++++++------------ upload_file.php | 39 +++++++++++++++------------------------ 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/index.php b/index.php index e00f42a..dd34a1c 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ Sign out'; @@ -19,8 +19,8 @@ if (isset($_GET) && count($_GET) > 0) { if (isset($_GET['signout'])) { if (isset($_COOKIE['password'])) { unset($_COOKIE['password']); - setcookie('password', null, -1, '/', $_SERVER['SERVER_NAME']); - header('Location: ' . $url); + setcookie("password", null, -1, "/", $_SERVER['SERVER_NAME']); + header("Location: " . $url); } } @@ -28,14 +28,14 @@ if ($_POST && $pass) { if ((hash("sha256", $_POST['password']) == $pass)) { if (isset($_POST['rememberme'])) { /* Set cookie to last 1 year */ - setcookie('password', hash("sha256", $_POST['password']), time()+60*60*24*365, '/', $_SERVER['SERVER_NAME'] ); + setcookie("password", hash("sha256", $_POST['password']), time()+60*60*24*365, "/", $_SERVER['SERVER_NAME'] ); } else { /* Cookie expires when browser closes */ - setcookie('password', hash("sha256", $_POST['password']), false, '/', $_SERVER['SERVER_NAME'] ); + setcookie("password", hash("sha256", $_POST['password']), false, "/", $_SERVER['SERVER_NAME'] ); } - header('Location: ' . $url . $getstring); + header("Location: " . $url . $getstring); } else { - header('Location: ' . $url); + header("Location: " . $url); exit(); } } else if ($pass) { @@ -46,7 +46,7 @@ if ($_POST && $pass) { <?php echo $logontitle ?> @@ -67,7 +67,7 @@ if ($_POST && $pass) { $signout = ""; } -function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s') { +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; @@ -200,7 +200,7 @@ while ($this_array = each($ordered_array)) { } } - $fileparts = explode('.', strtolower($value)); + $fileparts = explode(".", strtolower($value)); $icon = "unknown"; switch ($fileparts[count($fileparts)-1]) { @@ -297,7 +297,7 @@ while ($this_array = each($ordered_array)) { $icon="unknown"; break; } - + $listing[$listsize]['filename'] = utf8_encode($value); $listing[$listsize]['type'] = $icon; $listing[$listsize]['modified'] = $key; @@ -337,7 +337,7 @@ for ($i = 0; $i < count($listing); $i++) { $spaces = $spaces . " "; } - echo '[IMG] ' . $preview . '' . $spaces . date("d-M-Y H:i", $listing[$i]['modified']) . ' ' . size_readable($listing[$i]['size'], null, "bi") . ' ' . "\n"; + echo '[IMG] ' . $preview . "" . $spaces . date("d-M-Y H:i", $listing[$i]['modified']) . " " . size_readable($listing[$i]['size'], null, "bi") . " " . "\n"; } ?>
diff --git a/upload_file.php b/upload_file.php index a1b218e..890078a 100644 --- a/upload_file.php +++ b/upload_file.php @@ -1,4 +1,4 @@ - + @@ -9,7 +9,7 @@

0) - { - echo "Return Code: " . $_FILES["file"]["error"] . "
"; - } - 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"] . "
"; - $fileurl = "$url" . $_FILES["file"]["name"]; - echo "URL: $fileurl
"; - echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi"); - } - } +if ($_FILES["file"]["error"] > 0) { + echo "Return Code: " . $_FILES["file"]["error"] . "
"; +} 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"] . "
"; + $fileurl = "$url" . $_FILES["file"]["name"]; + echo "URL: $fileurl
"; + echo "Size: " . size_readable($_FILES["file"]["size"], null, "bi"); } -?> +} +?>

Back to index -- cgit v1.2.3