refactor many shits to make uploading module works with UniSkinAPI

This commit is contained in:
printempw 2016-01-17 15:56:36 +08:00
parent e012033a0a
commit 076ab6e5c9
7 changed files with 66 additions and 35 deletions

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
* @Last Modified time: 2016-01-17 15:14:43
* @Last Modified time: 2016-01-17 15:51:42
*
* All ajax requests will be handled here
*/
@ -84,7 +84,7 @@ if ($action == "login") {
} else if ($action == "upload") {
if ($_SESSION['token'] == $user -> getToken()) {
if (checkFile()) {
if ($file = $_FILES['skin_file']) {
if ($file = getValue('skin_file', $_FILES)) {
if ($user -> setTexture('skin', $file)) {
$json[0]['errno'] = 0;
$json[0]['msg'] = "Skin uploaded successfully.";
@ -93,7 +93,7 @@ if ($action == "login") {
$json[0]['msg'] = "Uncaught error.";
}
}
if ($file = $_FILES['cape_file']) {
if ($file = getValue('cape_file', $_FILES)) {
if ($user -> setTexture('cape', $file)) {
$json[1]['errno'] = 0;
$json[1]['msg'] = "Cape uploaded successfully.";
@ -136,7 +136,7 @@ function checkInput() {
function checkFile() {
global $json;
if (!($_FILES['skin_file'] || $_FILES['cape_file'])) {
if (!(getValue('skin_file', $_FILES) || getValue('cape_file', $_FILES))) {
$json['errno'] = 1;
$json['msg'] = "No input file selected.";
return false;
@ -144,36 +144,42 @@ function checkFile() {
/**
* Check for skin_file
*/
if (($_FILES["skin_file"]["type"] == "image/png") || ($_FILES["skin_file"]["type"] == "image/x-png")) {
if ((getValue('skin_file', $_FILES)["type"] == "image/png") || (getValue('skin_file', $_FILES)["type"] == "image/x-png")) {
// if error occured while uploading file
if ($_FILES["skin_file"]["error"] > 0) {
if (getValue('skin_file', $_FILES)["error"] > 0) {
$json['errno'] = 1;
$json['msg'] = $_FILES["skin_file"]["error"];
$json['msg'] = getValue('skin_file', $_FILES)["error"];
return false;
}
} else {
if ($_FILES["skin_file"]) {
if (getValue('skin_file', $_FILES)) {
$json['errno'] = 1;
$json['msg'] = 'Skin file type error.';
return false;
} else {
$json[0]['errno'] = 0;
$json[0]['msg'] = 'No skin file selected.';
}
}
/**
* Check for cape_file
*/
if (($_FILES["cape_file"]["type"] == "image/png") || ($_FILES["cape_file"]["type"] == "image/x-png")) {
if ((getValue('cape_file', $_FILES)["type"] == "image/png") || (getValue('cape_file', $_FILES)["type"] == "image/x-png")) {
// if error occured while uploading file
if ($_FILES["cape_file"]["error"] > 0) {
if (getValue('cape_file', $_FILES)["error"] > 0) {
$json['errno'] = 1;
$json['msg'] = $_FILES["cape_file"]["error"];
$json['msg'] = getValue('cape_file', $_FILES)["error"];
return false;
}
} else {
if ($_FILES["cape_file"]) {
if (getValue('cape_file', $_FILES)) {
$json['errno'] = 1;
$json['msg'] = 'Cape file type error.';
return false;
} else {
$json[1]['errno'] = 0;
$json[1]['msg'] = 'No cape file selected.';
}
}

View File

@ -56,7 +56,7 @@ $("body").on("click", "#login", function(){
docCookies.setItem("token", json.token, 604800, '/');
}
showMsg("alert-success", "Logging succeed!");
// window.setTimeout("window.location = './user.php'", 1000);
window.setTimeout("window.location = './user/index.php'", 1000);
} else {
showMsg("alert-danger", json.msg);
}

View File

@ -107,13 +107,14 @@ $("#upload").click(function(){
showMsg("alert-info", "Uploading...");
},
success: function(json) {
console.log(json);
if (json[0].errno == 0 && json[1].errno == 0) {
showMsg("alert-success", "Successfully uploaded.");
}
if (json[0].success != 0) {
if (json[0].errno != 0) {
showMsg("alert-danger", "Error when uploading skin:\n"+json[0].msg);
}
if (json[1].success != 0) {
if (json[1].errno != 0) {
showMsg("alert-danger", "Error when uploading cape:\n"+json[1].msg);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

File diff suppressed because one or more lines are too long