From 1e8cb89f379ab4f6bf31c26a2404863a2688b6f9 Mon Sep 17 00:00:00 2001 From: Yandols ZeonX Date: Sat, 24 Oct 2020 04:17:13 +0800 Subject: [PATCH] 2.2-R58/1.4 - The Return Proper Error Codes Update. This is a parity update that brings error codes from the live server onto the repository code. It was an experimental feature that allowed us to debug some problems instead of always returning Error 400 to the user, so I have no idea why it was not already on the repo. --- dropload.php | 24 ++++++++++++------------ upload.php | 46 ++++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/dropload.php b/dropload.php index 0b0518a..a185a13 100644 --- a/dropload.php +++ b/dropload.php @@ -1,8 +1,8 @@ 6291456) { $uploadOk = 0; - header('HTTP/1.1 400 Bad Request', true, 400); - http_response_code(400); + header('HTTP/1.1 413 Payload Too Large', true, 413); + http_response_code(413); return; } // Allow only certain file formats. @@ -41,8 +41,8 @@ if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg && $imageFileType != "gif" && $imageFileType != "svg" && $imageFileType != "GIF" && $imageFileType != "SVG" ) { $uploadOk = 0; - header('HTTP/1.1 400 Bad Request', true, 400); - http_response_code(400); + header('HTTP/1.1 415 Unsupported Media Type', true, 415); + http_response_code(415); return; } // Check if $uploadOk is set to 0 by an error, if so go to failure condition. @@ -109,8 +109,8 @@ if ($uploadOk == 0) { ]); return; } else { - header('HTTP/1.1 400 Bad Request', true, 400); - http_response_code(400); + header('HTTP/1.1 422 Unprocessable Entity', true, 422); + http_response_code(422); return; } } diff --git a/upload.php b/upload.php index f57cb09..d184e98 100644 --- a/upload.php +++ b/upload.php @@ -1,8 +1,8 @@ 6291456) { - echo "Sorry, your file is too large. (Max is 6MB)"; + //echo "Sorry, your file is too large. (Max is 6MB)"; + //header("HTTP/1.1 413 Payload Too Large"); + //header('Location: ./failed.php?error=413'); + $errCode = 413; $uploadOk = 0; - header('Location: ./failed.php'); } // Allow only certain file formats. // 1.1a -- Fixed uppercase rejection bug and allows them. @@ -38,14 +44,21 @@ if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "gif" && $imageFileType != "svg" && $imageFileType != "GIF" && $imageFileType != "SVG" ) { - echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; + //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; + //header("HTTP/1.1 415 Unsupported Media Type"); + //header('Location: ./failed.php?error=415'); + $errCode = 415; $uploadOk = 0; - header('Location: ./failed.php'); } // Check if $uploadOk is set to 0 by an error, if so go to failure condition. if ($uploadOk == 0) { - echo "Sorry, your file could not be uploaded."; - header('Location: ./failed.php'); + if (!$errCode) { + //echo "Sorry, your file could not be uploaded."; + header('Location: ./failed.php?error=400'); + } else { + //echo "Sorry, your file could not be uploaded."; + header('Location: ./failed.php?error=' . $errCode); + } // If everything is ok, try to upload file. } else { // 1.2a --- Changed some case-confusing characters such as I and O to web safe symbols. @@ -97,14 +110,15 @@ if ($uploadOk == 0) { $newtarget = $target_dir . $newfilename; if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newtarget)) { chmod("$newtarget", 0775); // Set read and write permissions on file - echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; + //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; $uploaderlog = "" . date('U') . ", ". date('Y-m-d H:i:s e') . ", $_SERVER[REMOTE_ADDR], $newfilename" . ", " . $imejicoreversion . ", $_SERVER[HTTP_USER_AGENT]"; file_put_contents('uploads.log', $uploaderlog . PHP_EOL, FILE_APPEND); header('Location: https://i.yandols.xyz/' . $newfilename); } else { // If anything wrong here, go to failure condition. - echo "Sorry, there was a problem uploading your file."; - header('Location: ./failed.php'); + //echo "Sorry, there was a problem uploading your file."; + // This part of code should never occur. But in case it does, redirect user to error page with code 500. + header('Location: ./failed.php?error=500'); } } ?>