1
0

59 lines
2.1 KiB
PHP

<?php
include ("connectsql.php");
include 'functions.php';
$author = htmlentities(trim($_POST[author]));
$name = htmlentities(trim($_POST[name]));
$license = htmlentities(trim($_POST[license]));
$dataUrl = str_replace(' ', '+', $_POST[img]); // the image will be injected via javascript and not using normal upload
$output = array('success' => false, 'status_msg' => 'UNKNOWN ERROR: could not save the Skin. unknown Error line 8');
$parts = explode(',', $dataUrl);
$bin = base64_decode($parts[1]); //image injected as bas64 string now decoded as binary string
$size = getimagesizefromstring($bin); // now at this point we get a GD object from base64 string image from uploaded injection
$output[img] = $size;
header('Content-Type: application/json');
if ($size[0] == 64 && $size[1] == 32 && $size[mime] == "image/png") {
if ($author && $name && $license) {
$output[success] = true;
$output[status_msg] = 'Upload sucessfull done';
}
else {
$output[success] = false;
$output[status_msg] = 'ERROR: could not save the Skin. missing param author or name or license';
}
}
else {
$valid = false;
$output[success] = false;
$output[status_msg] = 'ERROR: NOT a valid Skin file. only image/png and 64x32 skins are currently supported. (im working on a fix...)';
}
if ($output[success] == true) {
$sql = "SELECT `id`
FROM `mt_skins`
WHERE `img` = '$parts[1]'
LIMIT 0 , 1";
$query = mysql_query($sql);
$result = mysql_num_rows($query);
if ($result !== 0) {
$output[success] = false;
$output[status_msg]= "ERROR: the skin you trying to upload is already uploaded.";
}
else{
$sql = "INSERT INTO `mt_skins`( `name`, `author`, `license`,`uploaded`, `type`,`img`) VALUES ('$name','$author','$license',NOW(),'$size[mime]','$parts[1]')";
$a = mysql_query($sql);
$img = imagecreatefromstring($bin);
$id = mysql_insert_id();
$ok = save_images($img, $id); // this will genrate the 2d image plain view as a file into filesystem from the base64 image database, using a GD object image
if ($a == false) {
$output[success] = false;
$output[status_msg] = 'ERROR: could not save the Skin. Error in Mysql Sql says: {$a}';
}
}
}
echo json_encode($output);
?>