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.
YandolsZX 4 years ago
parent 758d095aa4
commit 1e8cb89f37
  1. 24
      dropload.php
  2. 46
      upload.php

@ -1,8 +1,8 @@
<?php <?php
// Imeji Uploader Core Code -- Version 2.1 (revision 54) (Uploader Filename Randomizer Algorithm Update) // Imeji Uploader Core Code -- Version 2.1 Revision 58 (Return Proper Error Codes Update)
// //
// Core Variables. Don't change unless you know what you're doing. // Core Variables. Don't change unless you know what you're doing.
$imejicoreversion = "Icarus_Imeji_V2.1_Droploader_r54"; $imejicoreversion = "Imeji-Caddy_V2.2_Droploader_R58";
$target_dir = "public/"; $target_dir = "public/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_filenameonly = basename($_FILES["fileToUpload"]["name"]); $target_filenameonly = basename($_FILES["fileToUpload"]["name"]);
@ -15,23 +15,23 @@ if(isset($_POST["submit"])) {
$uploadOk = 1; $uploadOk = 1;
} else { } else {
$uploadOk = 0; $uploadOk = 0;
header('HTTP/1.1 400 Bad Request', true, 400); header('HTTP/1.1 415 Unsupported Media Type', true, 415);
http_response_code(400); http_response_code(415);
return; return;
} }
} }
// Check whether a file with the same name already exists on server or not for security reasons. // Check whether a file with the same name already exists on server or not for security reasons.
if (file_exists($target_file)) { if (file_exists($target_file)) {
$uploadOk = 0; $uploadOk = 0;
header('HTTP/1.1 400 Bad Request', true, 400); header('HTTP/1.1 409 Conflict', true, 409);
http_response_code(400); http_response_code(409);
return; return;
} }
// Check file size. (Imeji Standard Max is 6MB) // Check file size. (Imeji Standard Max is 6MB)
if ($_FILES["fileToUpload"]["size"] > 6291456) { if ($_FILES["fileToUpload"]["size"] > 6291456) {
$uploadOk = 0; $uploadOk = 0;
header('HTTP/1.1 400 Bad Request', true, 400); header('HTTP/1.1 413 Payload Too Large', true, 413);
http_response_code(400); http_response_code(413);
return; return;
} }
// Allow only certain file formats. // Allow only certain file formats.
@ -41,8 +41,8 @@ if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg
&& $imageFileType != "gif" && $imageFileType != "svg" && $imageFileType != "gif" && $imageFileType != "svg"
&& $imageFileType != "GIF" && $imageFileType != "SVG" ) { && $imageFileType != "GIF" && $imageFileType != "SVG" ) {
$uploadOk = 0; $uploadOk = 0;
header('HTTP/1.1 400 Bad Request', true, 400); header('HTTP/1.1 415 Unsupported Media Type', true, 415);
http_response_code(400); http_response_code(415);
return; return;
} }
// Check if $uploadOk is set to 0 by an error, if so go to failure condition. // Check if $uploadOk is set to 0 by an error, if so go to failure condition.
@ -109,8 +109,8 @@ if ($uploadOk == 0) {
]); ]);
return; return;
} else { } else {
header('HTTP/1.1 400 Bad Request', true, 400); header('HTTP/1.1 422 Unprocessable Entity', true, 422);
http_response_code(400); http_response_code(422);
return; return;
} }
} }

@ -1,8 +1,8 @@
<?php <?php
// Imeji Uploader Core Code -- Version 1.3 (Uploader Filename Randomizer Algorithm Update) // Imeji Uploader Core Code -- Version 1.4 (Return Proper Error Codes Update)
// //
// Core Variables. Don't change unless you know what you're doing. // Core Variables. Don't change unless you know what you're doing.
$imejicoreversion = "imeji_v1.3_2"; $imejicoreversion = "Imeji-Caddy_V1.4";
$target_dir = "public/"; $target_dir = "public/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_filenameonly = basename($_FILES["fileToUpload"]["name"]); $target_filenameonly = basename($_FILES["fileToUpload"]["name"]);
@ -12,25 +12,31 @@ $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) { if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) { if($check !== false) {
echo "File is an image - " . $check["mime"] . "."; //echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1; $uploadOk = 1;
} else { } else {
echo "File is not an image."; //echo "File is not an image.";
//header("HTTP/1.1 415 Unsupported Media Type");
//header('Location: ./failed.php?error=415');
$errCode = 415;
$uploadOk = 0; $uploadOk = 0;
header('Location: ./failed.php');
} }
} }
// Check whether a file with the same name already exists on server or not for security reasons. // Check whether a file with the same name already exists on server or not for security reasons.
if (file_exists($target_file)) { if (file_exists($target_file)) {
echo "Sorry, file already exists."; //echo "Sorry, file already exists.";
//header("HTTP/1.1 409 Conflict");
//header('Location: ./failed.php?error=409');
$errCode = 409;
$uploadOk = 0; $uploadOk = 0;
header('Location: ./failed.php');
} }
// Check file size. (Imeji Standard Max is 6MB) // Check file size. (Imeji Standard Max is 6MB)
if ($_FILES["fileToUpload"]["size"] > 6291456) { if ($_FILES["fileToUpload"]["size"] > 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; $uploadOk = 0;
header('Location: ./failed.php');
} }
// Allow only certain file formats. // Allow only certain file formats.
// 1.1a -- Fixed uppercase rejection bug and allows them. // 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 != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG"
&& $imageFileType != "gif" && $imageFileType != "svg" && $imageFileType != "gif" && $imageFileType != "svg"
&& $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; $uploadOk = 0;
header('Location: ./failed.php');
} }
// Check if $uploadOk is set to 0 by an error, if so go to failure condition. // Check if $uploadOk is set to 0 by an error, if so go to failure condition.
if ($uploadOk == 0) { if ($uploadOk == 0) {
echo "Sorry, your file could not be uploaded."; if (!$errCode) {
header('Location: ./failed.php'); //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. // If everything is ok, try to upload file.
} else { } else {
// 1.2a --- Changed some case-confusing characters such as I and O to web safe symbols. // 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; $newtarget = $target_dir . $newfilename;
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newtarget)) { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newtarget)) {
chmod("$newtarget", 0775); // Set read and write permissions on file 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]"; $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); file_put_contents('uploads.log', $uploaderlog . PHP_EOL, FILE_APPEND);
header('Location: https://i.yandols.xyz/' . $newfilename); header('Location: https://i.yandols.xyz/' . $newfilename);
} else { } else {
// If anything wrong here, go to failure condition. // If anything wrong here, go to failure condition.
echo "Sorry, there was a problem uploading your file."; //echo "Sorry, there was a problem uploading your file.";
header('Location: ./failed.php'); // 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');
} }
} }
?> ?>

Loading…
Cancel
Save