Christopher hace 6 años
padre
commit
aa52f29f99
Se han modificado 4 ficheros con 41 adiciones y 6 borrados
  1. 1 1
      html/config.php
  2. 25 2
      html/core.php
  3. 1 0
      html/lang_strings.json
  4. 14 3
      html/upload.php

+ 1 - 1
html/config.php

@@ -22,7 +22,7 @@ $allowed_mime_types = array('image/png', 'image/jpeg', 'image/gif', 'video/webm'
 define("USERS_JSON", $_SERVER['DOCUMENT_ROOT'] . "/users.json");
 
 
-//	Description: Path to the user content directory. Must be writeable by the script. Do not include trailing slash.
+//	Description: Full path to the root of the user content directory. Must be writeable by the script. Do not include trailing slash.
 //	Default: "/u"
 //	Default Example: "https://ugc.dbmxpca.com/u/13940/3198590318.png"
 define("USER_CONTENT_DIR", $_SERVER['DOCUMENT_ROOT'] . "/u");

+ 25 - 2
html/core.php

@@ -92,6 +92,29 @@ function DIE_ERR($str){
 	}
 }
 
+//	Create the user directory within the UCD if it doesn't exist. Returns true on success or false on failure.
+function CREATE_USER_CONTENT_DIR($username){
+	
+	//	Attempt to create the directory if it doesn't exist.
+	$user_content_dir = USER_CONTENT_DIR . "/" . $username;
+	if (!file_exists($user_content_dir)){
+		
+		mkdir($user_content_dir, 0777, true); 
+	}
+	//	Check and make sure it now exists.
+	if (!file_exists($user_content_dir)){
+		return false;
+	}
+	
+	return true;
+}
+
+//	Returns full path to the user's directory within the UCD.
+function GET_USER_CONTENT_DIR_PATH($username){
+	
+	return USER_CONTENT_DIR . "/" . $username;
+}
+
 //	Check user authorization.
 function CHECK_USER(&$err){
 	
@@ -167,14 +190,14 @@ function CHECK_IMAGE_PRELIM_DATA(&$err){
 	
 	if (filesize($_FILES['image']['tmp_name']) > 0){
 		
-		if (isset($allowed_mime_types[$_FILES['image']['type']])){
+		if (!in_array($_FILES['image']['type'], $allowed_mime_types)){
 			
 			$err = null;
 			return true;
 		}
 		else{
 			
-			$err = "error_415_3";
+			$err = "error_415_1";
 			return false;
 		}
 	}

+ 1 - 0
html/lang_strings.json

@@ -14,6 +14,7 @@
 		"error_415": "Error 415: Unsupported Media Type.",
 		"error_415_1": "Error 415: Unsupported Media Type. Supported media types are PNG, JPEG, GIF, and webm.",
 		"error_500": "Error 500: Internal Server Error.",
+		"error_500_1": "Error 500: Internal Server Error. Failed to create user directory within the UCD.",
 		"e": "e"
 	}
 }

+ 14 - 3
html/upload.php

@@ -31,12 +31,23 @@ if (CHECK_USER($err)){
 	$err = null;
 	if (CHECK_IMAGE_PRELIM_DATA($err)){
 		
+		$err = null;
 		if (CHECK_IMAGE_ERRORS($err)){
 			
-			echo "ok";
-			
-			
+			//	Attempt to create user's directory within UCD.
+			if (CREATE_USER_CONTENT_DIR($_REQUEST['u'])){
+				
+				echo "ok";
+				
+				
+				
+			}
 			
+			else{
+				
+				$err = "500_1";
+				DIE_ERR($err);
+			}
 		}
 		else{